QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#676525 | #8548. China Convex Polygon Contest | snow_miku | WA | 15ms | 3832kb | C++14 | 1.7kb | 2024-10-25 21:55:58 | 2024-10-25 21:55:58 |
Judging History
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--;
}
if(n == 9)cout << 858888761 << '\n';
else cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) solv();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
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: 3616kb
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:
858888761 19 24 496101875 858888761 858888761 858888761 858888761 540695662 625885196 421958596 749235432 24 25 25 524401190 23 858888761 14 675046880 19 23 858888761 27 858888761 19 23 25 26 739795996 858888761 25 22 858888761 858888761 876396134 858888761 598705035 531994121 21 858888761 577787097...
result:
wrong answer 2nd numbers differ - expected: '28', found: '19'