結果

問題 No.1015 おつりは要らないです
ユーザー hipopohipopo
提出日時 2020-04-10 18:02:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,306 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 143,716 KB
実行使用メモリ 5,420 KB
最終ジャッジ日時 2024-04-29 05:09:31
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

ll div_ceil(ll x, ll d) { return (x + d - 1) / d; }

int main() {
    int n;
    vector<ll> c(3);
    cin >> n >> c;
    vector<ll> a(n);
    cin >> a;
    rep(i, n) a[i] = div_ceil(a[i] + 1, 1000) * 1000;

    priority_queue<ll> que;
    rep(i, n) que.push(a[i]);
    
    int ptr = 2;
    vector<ll> v = {1000, 5000, 10000};
    while (!que.empty()) {
        ll m = que.top(); que.pop();
        while (0 <= ptr && c[ptr] == 0) ptr--;
        if (ptr == -1) {
            cout << "No" << endl;
            return 0;
        }
        
        if (v[ptr] <= m) {
            ll use = min(c[ptr], m / v[ptr]);
            m -= use * v[ptr];
            c[ptr] -= use;
        }
        else {
            ll use = min(c[ptr], div_ceil(m, v[ptr]));
            m -= use * v[ptr];
            c[ptr] -= use;
        }
        
        if (0 < m) que.push(m);
    }
    cout << "Yes" << endl;
}
0