結果

問題 No.1015 おつりは要らないです
ユーザー okok
提出日時 2020-04-03 22:19:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,001 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 85,832 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-08-11 08:42:58
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 24 ms
4,684 KB
testcase_11 AC 26 ms
4,696 KB
testcase_12 AC 23 ms
4,700 KB
testcase_13 AC 25 ms
4,688 KB
testcase_14 AC 25 ms
4,548 KB
testcase_15 AC 23 ms
4,556 KB
testcase_16 AC 25 ms
4,680 KB
testcase_17 AC 25 ms
4,608 KB
testcase_18 AC 25 ms
4,664 KB
testcase_19 AC 25 ms
4,548 KB
testcase_20 AC 20 ms
4,668 KB
testcase_21 AC 21 ms
4,548 KB
testcase_22 AC 20 ms
4,692 KB
testcase_23 AC 20 ms
4,380 KB
testcase_24 AC 21 ms
4,688 KB
testcase_25 AC 20 ms
4,740 KB
testcase_26 AC 20 ms
4,540 KB
testcase_27 AC 21 ms
4,692 KB
testcase_28 AC 20 ms
4,724 KB
testcase_29 AC 20 ms
4,688 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 11 ms
4,676 KB
testcase_32 AC 11 ms
4,684 KB
testcase_33 AC 16 ms
4,740 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
// } ;
} fio;

bool solve(){
	
	int N, X, Y, Z;
	int sum = 0, con = 0;
	vector<int> A;
	vector<int> B;
	bool flag = true;
	
	cin>>N>>X>>Y>>Z;
	
	A.resize(N);
	B.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		
		A[i]++;
		
		sum += A[i];
		
		con += A[i] / 10000;
		
		B[i] = A[i] % 10000;
	}
	
	if(sum > X * 1000 + Y * 5000 + Z * 10000){
		return false;
		// flag = false;
	}
	
	
	
	// cout<<"con = "<<con<<endl;
	{
		int a, b, c;
		
		a = min(Z, con);
		
		Z   -= a;
		con -= a;
		
		b = min(Y/2, con);
		
		Y   -= b * 2;
		con -= b;
		
		if(Y && X >= 5 && con) {
			Y--;
			X -= 5;
			con--;
		}
		
		c = min(X/10, con);
	
		X   -= c * 10;
		con -= c;
	}
	// cout<<"con = "<<con<<endl;
	
	// cout<<"X = "<<X<<" Y = "<<Y<<" Z = "<<Z<<endl;
	
	if(con) {
		return false;
	}
	
	sort(B.begin(), B.end(), greater<int>());
	
	for(int i = 0; i < Z && i < N; i++){
		B[i] = 0;
	}
	
	sum = 0, con = 0;
	
	for(int i = 0; i < N; i++){
		// if(B[i].second % 1000 == 0) B[i].second++;
		
		sum += B[i];
		
		con += B[i] / 5000;
		
		B[i] = B[i] % 5000;
	}
	
	// cout<<"con = "<<con<<endl;
	
	sort(B.begin(), B.end(), greater<int>());
	
	if(sum > X * 1000 + Y * 5000 + Z * 10000){
		return false;
	}
	
	{
		int a, b, c;
		
		b = min(Y, con);
		
		Y   -= b;
		con -= b;
		
		
		c = min(X/5, con);
	
		X   -= c * 5;
		con -= c;
	}
	// cout<<"con = "<<con<<endl;
	if(con) {
		return false;
	}
	
	for(int i = 0; i < Y && i < N; i++){
		B[i] = 0;
	}
	
	for(int i = 0; i < N; i++){
		
		X -= (B[i] + 1000 - 1) / 1000;
	}
	
	if(X < 0) return false;
	
	return true;
}

signed main(){
	
	if(solve()) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
0