AtCoder Grand Contest 018

Submission #5915823

Source codeソースコード

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct coin {
    int x,y,z;
    bool operator<(const coin& a) const {
        return x-y < a.x-a.y;
    }
};

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    int n = x+y+z;
    vector<coin> a(n);
    priority_queue<int> que1,que2;
    vector<ll> sum1(z+1,0),sum2(z+1,0);
    for (int i = 0;i < n;++i) cin >> a[i].x >> a[i].y >> a[i].z;
    sort(a.begin(),a.end());
    for (int i = 0;i < y;++i) {
        sum1[0] += a[i].y;
        que1.push(a[i].z-a[i].y);
    }
    for (int i = y;i < y+z;++i) {
        que1.push(a[i].z-a[i].y);
        sum1[i-y+1] = sum1[i-y]+que1.top()+a[i].y;
        que1.pop();
    }
    for (int i = y+z;i < n;++i) {
        sum2[z] += a[i].x;
        que2.push(a[i].z-a[i].x);
    }
    for (int i = y+z-1;i >= y;--i) {
        que2.push(a[i].z-a[i].x);
        sum2[i-y] = sum2[i-y+1]+que2.top()+a[i].x;
        que2.pop();
    }
    ll ans = 0;
    for (int i = 0;i < z+1;++i) ans = max(ans,sum1[i]+sum2[i]);
    cout << ans << endl;
    return 0;
}

Submission

Task問題 C - Coins
User nameユーザ名 koikotya
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 800
Source lengthソースコード長 1478 Byte
File nameファイル名
Exec time実行時間 140 ms
Memory usageメモリ使用量 2688 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
All 800 / 800 sample_01.txt,sample_02.txt,sample_03.txt,sample_01.txt,sample_02.txt,sample_03.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt,subtask_1_26.txt,subtask_1_27.txt,subtask_1_28.txt,subtask_1_29.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 24 ms 640 KB
subtask_1_03.txt AC 40 ms 1024 KB
subtask_1_04.txt AC 70 ms 1536 KB
subtask_1_05.txt AC 81 ms 1664 KB
subtask_1_06.txt AC 104 ms 1920 KB
subtask_1_07.txt AC 25 ms 768 KB
subtask_1_08.txt AC 95 ms 2432 KB
subtask_1_09.txt AC 23 ms 768 KB
subtask_1_10.txt AC 81 ms 1664 KB
subtask_1_11.txt AC 140 ms 2300 KB
subtask_1_12.txt AC 123 ms 2048 KB
subtask_1_13.txt AC 131 ms 2320 KB
subtask_1_14.txt AC 136 ms 2560 KB
subtask_1_15.txt AC 134 ms 2428 KB
subtask_1_16.txt AC 109 ms 2428 KB
subtask_1_17.txt AC 109 ms 2688 KB
subtask_1_18.txt AC 113 ms 2688 KB
subtask_1_19.txt AC 113 ms 2560 KB
subtask_1_20.txt AC 131 ms 2048 KB
subtask_1_21.txt AC 126 ms 2560 KB
subtask_1_22.txt AC 130 ms 2044 KB
subtask_1_23.txt AC 133 ms 2440 KB
subtask_1_24.txt AC 134 ms 2428 KB
subtask_1_25.txt AC 108 ms 2172 KB
subtask_1_26.txt AC 107 ms 2496 KB
subtask_1_27.txt AC 113 ms 2688 KB
subtask_1_28.txt AC 112 ms 2560 KB
subtask_1_29.txt AC 1 ms 256 KB