QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#674468#8548. China Convex Polygon ContestospoasaWA 15ms5888kbC++141.6kb2024-10-25 15:56:362024-10-25 15:56:37

Judging History

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

  • [2024-10-25 15:56:37]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5888kb
  • [2024-10-25 15:56:36]
  • 提交

answer

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

LL a[N], b[N], val[N];
void solve()
{
    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];
    sort(b + 1, b + n + 1);

    deque <int> used;
    a[n + 1] = m;
    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 pa = n + 1, pb = n, 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 = used.size(); i >= 1; i--) {
        b[i] = used.back();
        used.pop_back();
    }
    pa = n + 1;
    LL ans = 0;

    priority_queue <LL> q;
    q.push(0);
    while(pa > 0 && pb > 0) {
        if(b[pb] >= m) {
            pb--;
            continue;
        }
        while(a[pa - 1] >= b[pb]) q.push(val[pa - 1]), pa--;
        if(q.top() >= a[pa] - b[pb]) {
            ans += q.top();
            q.pop();
        } 

        else {
            ans += a[pa] - b[pb];
            LL mx = q.top();
            q.pop();
            q.push(mx + b[pb] - a[pa - 1]);
            pa--;
        }
        pb--;
    }
    while(pb) {
        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--) solve();
    return 0;
}

详细

Test #1:

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

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

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:

739788591
22
24
548785306
28
896007054
21
814117186
540695662
727182688
441726827
759475944
28
27
28
524401190
24
20
14
675046880
24
25
29
28
28
19
23
28
28
819730903
755946410
28
26
28
567449679
891539003
189435812
642113783
531994121
23
23
679740045
27
21
29
443074932
23
26
548739504
29
17
8328741...

result:

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