A - Exchange
Source: atcoder
Difficulty: 300

Problem Statement
In Japan, there are six types of coins in circulation:
1
yen,
5
yen,
10
yen,
50
yen,
100
yen, and
500
yen. Answer the following question regarding these coins.
Mr. AtCoder's wallet contains
A
1
-yen coins,
B
5
-yen coins,
C
10
-yen coins,
D
50
-yen coins,
E
100
-yen coins, and
F
500
-yen coins.
He is planning to shop at
N
stores in sequence.
Specifically, at the
i
-th store
(1 \leq i \leq N)
, he plans to buy one item that costs
X_i
yen (including tax).
Giving and receiving change takes time, so he wants to choose his coins so that he can pay the
exact amount
at each store.
Determine if this is possible.
Constraints
0 \leq A \leq 200
0 \leq B \leq 200
0 \leq C \leq 200
0 \leq D \leq 200
0 \leq E \leq 200
0 \leq F \leq 200
1 \leq N \leq 10
1 \leq X_i \leq 10000 \ (1 \leq i \leq N)
All input values are integers.
Input
The input is given from Standard Input in the following format:
A
B
C
D
E
F
N
X_1
X_2
\cdots
X_N
Output
Print
Yes
if the objective is achievable, and
No
otherwise.
Sample Input 1
0 0 6 3 4 1
3
700 250 160
Sample Output 1
Yes
For example, he can make exact payments at all three stores as follows:
At the first store: Use two
100
-yen coins and one
500
-yen coin.
At the second store: Use five
10
-yen coins and two
100
-yen coins.
At the third store: Use one
10
-yen coin and three
50
-yen coins.
Sample Input 2
0 0 0 2 4 0
3
100 200 300
Sample Output 2
No
The total amount in the wallet is
500
yen, but a total payment of
100+200+300=600
yen is required, so it is impossible to purchase all the items.
Sample Input 3
0 0 0 0 8 8
1
250
Sample Output 3
No
There are no
50
-yen or smaller coins in the wallet, so it is impossible to pay exactly
250
yen.
Sample Input 4
20 5 9 7 10 6
5
177 177 177 177 177
Sample Output 4
Yes
Sample Input 5
17 5 9 7 10 6
5
177 177 177 177 177
Sample Output 5
No

C++ solution:
#include<bits/stdc++.h>
using namespace std;
void coY(){cout<<"Yes"<<endl;}
void coN(){cout<<"No"<<endl;}
int main(){
  int n,x,i,j;
  vector<int> v={1,5,10,50,100,500},k(6),m(6,0);
  for(j=0;j<6;j++) cin>>k[j];
  cin>>n;
  for(j=0;j<n;j++){
    cin>>x;
    for(i=5;i>=0;i--){
      m[i]+=x/v[i];
      x%=v[i];
    }
  }
  for(i=0;i<6;i++){
    k[i]-=m[i];
    for(j=0;j<i;j++){
      if(k[j]>0){
        k[i]+=k[j]*v[j]/v[i];
        k[j]%=v[i]/v[j];
      }
    }
    if(k[i]<0){coN(); return 0;}
  }
  coY();
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt32)
	// use getI(), getS(), getInts(), getF()

	coinPrices := []int{1, 5, 10, 50, 100, 500}
	coinCounts := getInts(6)
	n := getI()
	x := getInts(n)
	for i := 0; i < n; i++ {
		xi := x[i]
		for j := 5; j >= 0; j-- {
			dc := min(xi/coinPrices[j], coinCounts[j])
			coinCounts[j] -= dc
			xi -= dc * coinPrices[j]
		}
		if xi > 0 {
			out("No")
			return
		}
	}
	out("Yes")
}

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func outStrings(x []string) {
	out(strings.Join(x, " "))
}

func outInts(x []int) {
	y := make([]string, len(x))
	for i := 0; i < len(x); i++ {
		y[i] = strconv.Itoa(x[i])
	}
	outStrings(y)
}

func getI() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	sc.Scan()
	return sc.Text()
}

// min, max, aSub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nMin(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nMax(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func chMin(a *int, b int) bool {
	if *a < b {
		return false
	}
	*a = b
	return true
}

func chMax(a *int, b int) bool {
	if *a > b {
		return false
	}
	*a = b
	return true
}

func aSub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

Java solution:
import java.util.*; import java.io.*; import java.math.*;
import java.util.concurrent.*;
import java.text.*;
public class Main{
	//見なくていいよ　ここから------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			try{
				BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
				while((read = br.readLine()) != null){
					inputLine.addAll(Arrays.asList(read.split(" ")));
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object... t){System.err.print("debug:");System.err.println(Arrays.deepToString(t));}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<String> nextStrArray(int size){
		ArrayList<String> ret = new ArrayList<>(size);
		for(int i = 0; i < size; i++){
			ret.add(next());
		}
		return ret;
	}
	static ArrayList<Integer> nextIntArray(int size){
		ArrayList<Integer> ret = new ArrayList<>(size);
		for(int i = 0; i < size; i++){
			ret.add(Integer.parseInt(next()));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(int size){
		ArrayList<Long> ret = new ArrayList<>(size);
		for(int i = 0; i < size; i++){
			ret.add(Long.parseLong(next()));
		}
		return ret;
	}
	@SuppressWarnings("unchecked")
	static String myconv(Object list, int no){//only join
		StringBuilder sb = new StringBuilder("");
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof long[]){
			long[] tmp = (long[])list;
			if(tmp.length == 0){
				return "";
			}
			sb.append(String.valueOf(tmp[0]));
			for(int i = 1; i < tmp.length; i++){
				sb.append(joinString).append(String.valueOf(tmp[i]));
			}
			return sb.toString();
		}else if(list instanceof int[]){
			int[] tmp = (int[])list;
			if(tmp.length == 0){
				return "";
			}
			sb.append(String.valueOf(tmp[0]));
			for(int i = 1; i < tmp.length; i++){
				sb.append(joinString).append(String.valueOf(tmp[i]));
			}
			return sb.toString();
		}else if(list instanceof ArrayList){
			ArrayList tmp = (ArrayList)list;
			if(tmp.size() == 0){
				return "";
			}
			sb.append(tmp.get(0));
			for(int i = 1; i < tmp.size(); i++){
				sb.append(joinString).append(tmp.get(i));
			}
			return sb.toString();
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	static ArrayList<String> myconv(String str, String no){
		return new ArrayList<String>(Arrays.asList(str.split(no)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//見なくていいよ　ここまで------------------------------------------
	//このコードをコンパイルするときは、「-encoding UTF-8」を指定すること
	static void solve(){//ここがメイン関数
		int[] list = new int[6];
		for(int i = 0; i < 6; i++){
			list[i] = nextInt();
		}
		int N = nextInt();
		int[] sc = {1,5,10,50,100,500};
		for(int i = 0; i < N; i++){
			int X = nextInt();
			for(int j = sc.length - 1; 0 <= j; j--){
				int d = Math.min(X / sc[j], list[j]);
				X -= d * sc[j];
				list[j] -= d;
			}
			if(X > 0){
				myout("No");
				return;
			}
		}
		myout("Yes");
	}
	//メソッド追加エリア　ここから



	//メソッド追加エリア　ここまで
}

JavaScript solution:
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  var q = 1;
  while(q--)print(solve());
}

function solve(){
  var a = nexts(6);
  var n = next();
  var b = [1,5,10,50,100,500];
  for(var i = 0; i < n; i++){
    var x = next();
    for(var j = 5; j >= 0; j--){
      var t = x / b[j] | 0;
      t = Math.min(t, a[j]);
      x -= t * b[j];
      a[j] -= t;
    }
    if(x)return "No";
  }
  return "Yes";
}

Python solution:
def main():
    import sys
    A, B, C, D, E, F = map(int, sys.stdin.readline().split())
    N = int(sys.stdin.readline())
    X = list(map(int, sys.stdin.readline().split()))
    
    # Define coin values and their counts
    coins = [1, 5, 10, 50, 100, 500]
    counts = [A, B, C, D, E, F]
    
    for x in X:
        target = x
        # Try to make the amount 'target' with available coins
        new_counts = counts.copy()
        for i in range(len(coins)-1, -1, -1):
            coin = coins[i]
            count = new_counts[i]
            # Use as many of this coin as possible without exceeding target
            num = min(count, target // coin)
            target -= num * coin
            new_counts[i] -= num
            if target == 0:
                break
        # If target is not zero, it's impossible to make the exact amount
        if target != 0:
            print("No")
            return
        # Update the counts with the used coins
        counts = new_counts
    print("Yes")

if __name__ == "__main__":
    main()

Ruby solution:
s = gets.chomp.split.map(&:to_i)
t = [1, 5, 10, 50, 100, 500]
n = gets.to_i
x = gets.chomp.split.map(&:to_i)
x.each do |v|
  i = 5
  while i >= 0
    need = v / t[i]
    if need >= s[i]
      v -= s[i] * t[i]
      s[i] = 0
    else
      v -= need * t[i]
      s[i] -= need
    end
    i -= 1
  end
  if v != 0
    puts "No"
    exit
  end
end
puts "Yes"