QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220829#7523. Partially Free Mealammardab3an#WA 388ms23496kbC++141.4kb2023-10-20 21:13:292023-10-20 21:13:30

Judging History

你现在查看的是最新测评结果

  • [2023-10-20 21:13:30]
  • 评测
  • 测评结果:WA
  • 用时:388ms
  • 内存:23496kb
  • [2023-10-20 21:13:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main()
{

    int n;
    cin >> n;

    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];

    multiset<pair<int, int>> f, s, t;

    for(int i = 0; i < n; i++){
        f.insert({b[i], i});
        s.insert({b[i]+a[i], i});
    }

    ll ans = 0;

    int maxB = 0;
    for(int i = 1; i <= n; i++){
        ll can1 = 1e18, can2 = 1e18, idx1, idx2;
        if(!s.empty()){
            auto [x, y] = *s.begin();
            can1 = x;
            idx1 = y;
        }
        if(!t.empty()){
            auto [x, y] = *t.begin();
            can2 = x;
            idx2 = y;
        }
        if(can1 < can2){
            ans -= maxB;
            ans += can1;
            maxB = max(maxB, b[idx1]);
            f.erase({b[idx1], idx1});
            s.erase({b[idx1] + a[idx1], idx1});
            t.erase({a[idx1], idx1});
        } else {
            ans += can2;
            maxB = max(maxB, b[idx2]);
            f.erase({b[idx2], idx2});
            s.erase({b[idx2] + a[idx2], idx2});
            t.erase({a[idx2], idx2});
        }
        while(!f.empty() && (*f.begin()).first <= maxB){
            auto [x, y] = *f.begin();
            f.erase(f.begin());
            s.erase({a[y]+b[y], y});
            t.insert({a[y], y});
        }
        cout << ans << "\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 388ms
memory: 23496kb

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:

1318594
3208018
5570526
7834517
9604836
11487338
13751811
16969221
20474954
24404868
27185508
28934506
30733498
32650895
36798142
41368806
46006583
50861881
56152566
57180946
62908531
68894403
75126253
77007580
80435220
84466525
91588239
93073786
95712460
102765748
110136907
111129180
112091754
1134...

result:

wrong answer 4th lines differ - expected: '7340845', found: '7834517'