結果

問題 No.1015 おつりは要らないです
ユーザー erbowl
提出日時 2020-04-04 09:21:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 174,172 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 23:20:46
合計ジャッジ時間 3,417 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,x,y,z;
    std::cin >> n>>x>>y>>z;
    
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    priority_queue<ll> pq;
    for (int i = 0; i < n; i++) {
        pq.push((a[i]+1000)/1000);
    }
    
    while(pq.size()&&z>0){
        auto now = pq.top();pq.pop();
        if(now<=10){
            z--;
            continue;
        }
        if(now/10 <= z ){
            z -= now/10;
            now %= 10;
        }else{
            now -= z*10;
            z = 0;
        }
        if(now!=0)pq.push(now);
    }
    if(pq.size()==0){
        std::cout << "Yes" << std::endl;
        return 0;
    }
    while(pq.size()&&y>0){
        auto now = pq.top();pq.pop();
        if(now<=5){
            y--;
            continue;
        }
        if(now/5 <= y ){
            y -= now/5;
            now %= 5;
        }else{
            now -= y*5;
            y = 0;
        }
        if(now!=0)pq.push(now);
    }
    
    if(pq.size()==0){
        std::cout << "Yes" << std::endl;
        return 0;
    }
    
    while(pq.size()&&x>0){
        auto now = pq.top();pq.pop();
        if(x>=now){
            x -= now;
            continue;
        }else{
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    if(pq.size()==0){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

}

0