結果

問題 No.1015 おつりは要らないです
ユーザー leaf_1415leaf_1415
提出日時 2020-04-06 03:44:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,315 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 5,356 KB
最終ジャッジ日時 2023-09-18 14:09:01
合計ジャッジ時間 3,506 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 19 ms
4,912 KB
testcase_11 AC 19 ms
4,928 KB
testcase_12 AC 18 ms
4,936 KB
testcase_13 AC 18 ms
4,916 KB
testcase_14 AC 19 ms
4,932 KB
testcase_15 AC 17 ms
4,748 KB
testcase_16 AC 19 ms
4,772 KB
testcase_17 AC 19 ms
4,932 KB
testcase_18 AC 18 ms
4,772 KB
testcase_19 AC 18 ms
4,856 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 11 ms
4,820 KB
testcase_32 AC 11 ms
4,936 KB
testcase_33 AC 18 ms
4,856 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 2 ms
4,380 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;
	}
	
	for(int i = 1; i <= n; i++){
		if(a[i] < 5) vec.push_back(a[i]);
		else vec2.push_back(a[i]);
	}
	if(z > (int)vec.size() + (int)vec2.size()){
		cout << "Yes" << endl;
		return 0;
	}
	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+1 > (int)vec2.size() || z-(i+1) < 0) break;
		cnt[vec2[i+1]]--;
		cnt[vec[z-(i+1)]]++;
	}
	cout << "No" << endl;
	
	return 0;
}
0