QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#545846 | #8548. China Convex Polygon Contest | lonelywolf | WA | 14ms | 3560kb | C++20 | 1.2kb | 2024-09-03 17:40:39 | 2024-09-03 17:40:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n + 2);
a[0] = 0, a[n + 1] = m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> b[i];
b[i] += b[i - 1];
}
int j = n;
while (j >= 1 && b[j] > m) {
j--;
}
priority_queue<int> q;
int ans = 0;
for (int i = n; i >= 0; i--) {
int l = a[i], r = a[i + 1];
vector<int> t;
while (j >= 1 && b[j] >= l) {
t.push_back(b[j]);
j--;
}
if (!t.size()) {
q.push(r - l);
continue;
}
for (int i = 0; i < (int)t.size() - 1; i++) {
if (q.empty()) {
break;
}
ans += q.top();
q.pop();
}
if (q.empty()) {
ans += r - t.back();
q.push(t.back() - l);
continue;
}
if (r - t.back() <= q.top()) {
ans += q.top();
q.pop();
q.push(r - l);
} else {
ans += r - t.back();
auto s = q.top();
q.pop();
q.push(s + t.back() - l);
}
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 14ms
memory: 3560kb
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:
740552446 26 23 508883916 28 820816836 25 769874714 942603170 631257931 492186961 454332137 24 27 26 703954964 18 25 26 646348792 25 23 26 26 25 28 27 27 24 680432876 686942822 26 26 24 710720807 751241131 526383075 727826477 909314391 26 28 813993374 25 23 29 429433659 23 22 504593826 21 22 7111523...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '740552446'