結果

問題 No.1015 おつりは要らないです
ユーザー leaf_1415leaf_1415
提出日時 2020-04-06 03:49:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,278 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 85,716 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 05:08:17
合計ジャッジ時間 2,572 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 18 ms
5,376 KB
testcase_13 AC 18 ms
5,376 KB
testcase_14 AC 20 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 19 ms
5,376 KB
testcase_18 AC 18 ms
5,376 KB
testcase_19 AC 17 ms
5,376 KB
testcase_20 AC 17 ms
5,376 KB
testcase_21 AC 17 ms
5,376 KB
testcase_22 AC 17 ms
5,376 KB
testcase_23 AC 17 ms
5,376 KB
testcase_24 AC 18 ms
5,376 KB
testcase_25 AC 17 ms
5,376 KB
testcase_26 AC 17 ms
5,376 KB
testcase_27 AC 18 ms
5,376 KB
testcase_28 AC 17 ms
5,376 KB
testcase_29 AC 18 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 12 ms
5,376 KB
testcase_32 AC 11 ms
5,376 KB
testcase_33 AC 18 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, x, y, z;
llint a[100005];
vector<llint> vec, vec2;
llint cnt[15];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x >> y >> z;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i] = (a[i]+1000) / 1000;
	
	for(int i = 1; i <= n; i++){
		llint t = min(z, a[i]/10);
		z -= t;
		a[i] -= t * 10;
	}
	
	if(z == 0){
		for(int i = 1; i <= n; i++){
			llint t = min(y, a[i]/5);
			y -= t;
			a[i] -= t * 5;
			vec.push_back(a[i]);
		}
		sort(vec.rbegin(), vec.rend());
		for(int i = 0; i < vec.size(); i++){
			if(y > 0) y--;
			else x -= vec[i];
		}
		if(x >= 0) cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}
	
	if(z >= n){
		cout << "Yes" << endl;
		return 0;
	}
	for(int i = 1; i <= n; i++){
		if(a[i] < 5) vec.push_back(a[i]);
		else vec2.push_back(a[i]);
	}
	
	sort(vec.rbegin(), vec.rend());
	sort(vec2.rbegin(), vec2.rend());
	
	llint l = max(0LL, z - (llint)vec.size());
	for(int i = z-l; i < vec.size(); i++) cnt[vec[i]]++;
	for(int i = l; i < vec2.size(); i++) cnt[vec2[i]]++;
	
	llint orgy = y, orgx = x;
	for(int i = l; i <= z; i++){
		//for(int j = 0; j <= 9; j++) cout << cnt[j] << " "; cout << endl;
		y = orgy, x = orgx;
		llint cnt2[15];
		for(int j = 0; j < 10; j++) cnt2[j] = cnt[j];
		for(int j = 9; j >= 5; j--){
			llint t = min(cnt2[j], y);
			y -= t;
			cnt2[j] -= t;
			cnt2[j-5] += t;
		}
		for(int j = 4; j >= 0; j--){
			llint t = min(cnt2[j], y);
			y -= t;
			cnt2[j] -= t;
		}
		for(int j = 0; j <= 9; j++) x -= j * cnt2[j];
		if(x >= 0){
			cout << "Yes" << endl;
			return 0;
		}
		
		if(i >= (int)vec2.size() || z-i-1 < 0) break;
		cnt[vec2[i]]--;
		cnt[vec[z-i-1]]++;
	}
	cout << "No" << endl;
	
	return 0;
}
0