QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#545934 | #8548. China Convex Polygon Contest | HTensor | WA | 12ms | 3628kb | C++17 | 2.0kb | 2024-09-03 18:18:02 | 2024-09-03 18:18:02 |
Judging History
answer
#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x << ": " << x << "\n"
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
const int inf = 0x3f3f3f3f3f3f3f3fLL;
void solve() {
int n, m; cin >> n >> m;
vector<int> a(n + 2), b(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
a[n + 1] = m;
sort(b.begin() + 1, b.end());
for(int i = 1; i <= n; i++) {
cin >> b[i];
b[i] += b[i - 1];
}
if(n == 1) {
cout << min(0LL, b[1] - a[1]) << "\n";
return ;
}
int p = (--lower_bound(b.begin(), b.end(), m)) - b.begin(), ans = 0;
priority_queue<int> Q;
for(int i = n + 1; i; i--) {
int ed = p, st = p;
while(st > 0 && a[i - 1] <= b[st] && b[st] < a[i]) --st;
if(ed == st) {
Q.push(a[i] - a[i - 1]);
continue;
}
for(int j = st + 2; j <= ed; j++) {
if(!Q.empty()) {
ans += Q.top(); Q.pop();
}
}
if(ed != st) {
++st;
if(Q.empty()) {
ans += a[i] - b[st];
Q.push(b[st] - a[i - 1]);
} else if(a[i] - b[st] <= Q.top()) {
ans += Q.top(); Q.pop();
} else {
ans += a[i] - b[st];
int x = Q.top(); Q.pop();
Q.push(x + b[st] - a[i - 1]);
}
}
p = st - 1;
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int T; cin >> T;
while(T--) solve();
return 0;
}
/*
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
9 879847766
125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083
99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 12ms
memory: 3628kb
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:
593977603 22 14 508883916 21 746542610 23 711338895 887860335 631257931 483857805 454332137 24 23 20 660366943 18 22 17 646348792 21 19 22 23 24 28 23 19 22 665804988 686942822 21 25 19 685468028 672275425 475042920 727826477 727750180 22 24 741801365 24 20 29 386182981 21 18 504593826 20 14 5906888...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '593977603'