結果

問題 No.1015 おつりは要らないです
ユーザー ok
提出日時 2020-04-03 22:01:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,090 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 91,336 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-07-03 02:45:48
合計ジャッジ時間 3,038 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 28 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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<pair<int,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];
		
		sum += A[i];
		
		con += A[i] / 10000;
		
		B[i] = {A[i] % 10000, A[i]};
	}
	
	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;
		con -= b;
		
		if(Y && X >= 5 && con) {
			Y--;
			X -= 5;
			con--;
		}
		
		c = min(X/10, con);
	
		X   -= c;
		con -= c;
	}
	// cout<<"con = "<<con<<endl;
	
	// cout<<"X = "<<X<<" Y = "<<Y<<" Z = "<<Z<<endl;
	
	if(con) {
		return false;
	}
	
	sort(B.begin(), B.end(), greater<pair<int,int>>());
	
	for(int i = 0; i < Z && i < N; i++){
		B[i] = {0, 0};
	}
	
	sum = 0, con = 0;
	
	for(int i = 0; i < N; i++){
		B[i].second %= 10000;
		
		sum += B[i].second;
		
		con += B[i].second / 5000;
		
		B[i] = {B[i].second % 5000, B[i].second};
	}
	
	// cout<<"con = "<<con<<endl;
	
	sort(B.begin(), B.end(), greater<pair<int,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/2, con);
	
		X   -= c;
		con -= c;
	}
	// cout<<"con = "<<con<<endl;
	if(con) {
		return false;
	}
	
	for(int i = 0; i < Y && i < N; i++){
		B[i] = {0, 0};
	}
	
	for(int i = 0; i < N; i++){
		B[i].second %= 5000;
		
		if(B[i].second) {
			X -= (B[i].second + 1000 - 1) / 1000;
		}
	}
	
	if(X < 0) return false;
	
	return true;
}

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