QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660681#8548. China Convex Polygon Contesthjxddl#WA 13ms3720kbC++201.6kb2024-10-20 12:40:362024-10-20 12:40:36

Judging History

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

  • [2024-10-20 12:40:36]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3720kb
  • [2024-10-20 12:40:36]
  • 提交

answer

// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
void solve() {
    ll n, m;
    std::cin >> n >> m;
    std::vector<ll> a(n + 5), b(n + 5);
    for (int i = 1; i <= n; i++)
        std::cin >> a[i];
    for (int i = 1; i <= n; i++)
        std::cin >> b[i];
    a[n + 1] = m;
    std::sort(b.begin() + 1, b.begin() + n + 1);
    for (int i = 1; i <= n; i++) {
        b[i] += b[i - 1];
        // std::cout << b[i] << " ";
    }
    // std::cout << '\n';
    std::priority_queue<ll> q;
    int j = n;
    while (b[j] > m) j--;
    ll ans = 0;
    for (int i = n; i >= 1; i--) {
        bool vis = 0;
        while (q.size() && j > 1 && a[i] <= b[j - 1]) {
            ans += q.top();
            q.pop();
            j--;
        }
        if (a[i] > b[j])
            q.push(a[i + 1] - a[i]);
        else {
            if (q.size() && a[i + 1] - b[j] < q.top()) {
                ans += q.top();
                q.pop();
                q.push(a[i + 1] - a[i]);
                j--;
            } else {
                ans += a[i + 1] - b[j];
                if (q.size()) {
                    int x = q.top() + b[j] - a[i];
                    q.pop();
                    q.push(x);
                }
                j--;
            }
        }
    }
    std::cout << ans << '\n';
}
int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    int t = 1;
    std::cin >> t;
    while (t--) {
        solve();
    }
    std::cout << std::flush;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3476kb

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:

683472444
19
20
508883916
27
873591069
16
778674670
479667739
720683076
357844407
102148465
27
26
27
455838261
19
17
11
604107903
22
15
29
26
28
16
20
26
27
721470450
741603286
27
24
21
492282312
868779973
118657929
500364054
442706433
21
21
593883136
19
18
29
399824254
21
20
496116457
27
12
6782153...

result:

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