QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545942#8548. China Convex Polygon ContestHTensorWA 13ms3624kbC++172.1kb2024-09-03 18:21:082024-09-03 18:21:08

Judging History

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

  • [2024-09-03 18:21:08]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3624kb
  • [2024-09-03 18:21:08]
  • 提交

answer

#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x  << ": " << x << "\n"
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
const int inf = 0x3f3f3f3f3f3f3f3fLL;

void solve() {
    int n, m; cin >> n >> m; 
    vector<int> a(n + 2), b(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    a[n + 1] = m;

    
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    sort(b.begin() + 1, b.end());
    for(int i = 1; i <= n; i++) b[i] += b[i - 1];

    // if(n == 1) {
    //     cout << min(0LL, b[1] - a[1]) << "\n";
    //     return ;
    // }

    int p = (--lower_bound(b.begin(), b.end(), m)) - b.begin(), ans = 0;
    priority_queue<int> Q;
    for(int i = n + 1; i; i--) {
        int ed = p, st = p;
        while(st > 0 && a[i - 1] <= b[st] && b[st] < a[i]) --st;
        if(ed == st) {
            Q.push(a[i] - a[i - 1]);
            continue;
        }

        for(int j = st + 2; j <= ed; j++) {
            if(!Q.empty()) {
                ans += Q.top(); Q.pop();      
            }
        }

        
        if(ed != st) {
            ++st;
            if(Q.empty()) {
                ans += a[i] - b[st];
                Q.push(b[st] - a[i - 1]);
            } else if(a[i] - b[st] <= Q.top()) {
                ans += Q.top(); Q.pop();
            } else {
                ans += a[i] - b[st];
                int x = Q.top(); Q.pop();
                Q.push(x + b[st] - a[i - 1]);
            }
        }
        p = st - 1;
    }
    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T; cin >> T;
    while(T--) solve();
    return 0;
}

/*
3
3 10
1 5 9
1 2 3
3 10
1 5 9
1 1 4
3 10
1 5 9
1 5 10




9 879847766
125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083
99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 10
1 5 9
1 2 3
3 10
1 5 9
1 1 4
3 10
1 5 9
1 5 10

output:

9
9
7

result:

ok 3 number(s): "9 9 7"

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 3624kb

input:

10000
9 879847766
125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083
99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599
8 30
5 12 16 19 20 23 25 27
3 1 1 4 2 8 2 3
8 30
4 10 13 16 17 20 23 27
6 3 1 2 3 4 7 2
7 586479012
37693706 ...

output:

716252236
24
23
409209037
25
794950919
21
752408423
785558492
621536310
469036020
706179245
24
24
24
861816037
26
27
27
553214916
26
26
27
24
26
26
21
19
24
819730903
658017718
24
23
24
585282571
812573297
530484577
817190966
589486380
26
18
852449161
25
27
18
445306558
16
24
330964067
26
23
7835843...

result:

wrong answer 1st numbers differ - expected: '858888761', found: '716252236'