QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#676506#8548. China Convex Polygon Contestsnow_mikuWA 15ms3792kbC++141.7kb2024-10-25 21:53:192024-10-25 21:53:21

Judging History

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

  • [2024-10-25 21:53:21]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3792kb
  • [2024-10-25 21:53:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ll = long long;
const int N = 1e5 + 10;

LL a[N], b[N], val[N];
void solv()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    a[n + 1] = m;
    sort(b + 1, b + n + 1);
    for(int i = 1; i <= n; i++) b[i] += b[i - 1];
    for(int i = 1; i <= n; i++) val[i] = a[i + 1] - a[i];
    
    int pb = n;
    for(int i = n; i >= 1; i--) {
        if(b[i] >= m) pb = i - 1;
        else break;
    }

    deque <LL> used;
    int pa = n + 1, sa = 0;
    while(pa > 0 && pb > 0) {
        while(a[pa] >= b[pb]) sa++, pa--;
        used.push_front(b[pb]);
        if(used.size() > sa) used.pop_back();
        pb--;
    }

    pb = used.size();
    for(int i = pb; i >= 1; i--) {
        b[i] = used.back();
        used.pop_back();
    }

    priority_queue <LL> q;
    q.push(0);
    pa = n + 1;
    LL ans = 0;
    b[pb + 1] = 1e10;
    while(pa > 0 && pb > 0) {
        while(a[pa - 1] >= b[pb]) q.push(val[pa - 1]), pa--;
        if(q.top() >= min(a[pa], b[pb + 1]) - b[pb]) {
            ans += q.top();
            q.pop();
        }
        else {
            ans += min(a[pa], b[pb + 1]) - b[pb];
            LL tp = q.top();
            q.pop();
            q.push(tp + b[pb] - max(a[pa - 1], b[pb - 1]));
            pa--;
        }
        pb--;
    }
    while(pb > 0) {
        ans += q.top();
        q.pop();
        pb--;
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) solv();
    return 0;
}

详细

Test #1:

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

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: 15ms
memory: 3604kb

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:

618391700
19
24
496101875
28
777240758
21
678011489
540695662
625885196
421958596
749235432
24
25
25
524401190
23
17
14
675046880
19
23
28
27
22
19
23
25
26
739795996
719757922
25
22
27
567449679
876396134
189435812
598705035
531994121
21
21
577787097
24
19
27
443074932
22
24
548739504
25
17
7501555...

result:

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