QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666194 | #8548. China Convex Polygon Contest | WedonotLikeStudying# | WA | 15ms | 3668kb | C++20 | 1.7kb | 2024-10-22 17:01:17 | 2024-10-22 17:01:51 |
Judging History
answer
#include<bits/stdc++.h>
#define MAXN 100000
#define rep(i,j,k) for (int i=(j);i<=(k);++i)
#define dep(i,j,k) for (int i=(j);i>=(k);--i)
using namespace std;
typedef long long LL;
priority_queue <int> grd;
int a[MAXN+5];
LL b[MAXN+5];
void solve() {
int n,m;
cin>>n>>m;
rep(i,1,n) cin>>a[i];
rep(i,1,n) cin>>b[i];
sort(b+1,b+n+1);
rep(i,1,n) b[i]+=b[i-1];
a[n+1]=m;
int l=1,r=1;
LL ans=0;
while (!grd.empty()) grd.pop();
rep(i,1,n+1) {
while (l<=n&&b[l]<a[i-1]) ++l;
while (r<=n&&b[r]<a[i]) ++r;
if (l<r) {
if (!grd.empty()) {
if (a[i]-a[i-1]+grd.top()>a[i]-b[l]) {
ans+=a[i]-a[i-1]+grd.top();
grd.pop();
grd.push(-a[i]+a[i-1]);
grd.push(0);
} else {
ans+=a[i]-b[l];
if (a[i]-a[i-1]+grd.top()>0) {
int tmp=a[i]-a[i-1]+grd.top();
grd.push(-a[i]+b[l]+tmp);
} else grd.push(-a[i]+b[l]);
}
} else {
ans+=a[i]-b[l];
grd.push(-a[i]+b[l]);
}
rep(j,l+1,r-1) {
grd.push(0);
}
} else {
if (!grd.empty()) {
if (a[i]-a[i-1]+grd.top()>0) {
ans+=a[i]-a[i-1]+grd.top();
grd.pop();
grd.push(-a[i]+a[i-1]);
}
}
}
}
cout<<ans<<"\n";
return;
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
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: 3668kb
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 29 27 548785306 29 875933380 28 803763192 942603170 720683076 536166430 759475944 29 28 28 886112586 28 29 29 727698126 29 29 29 28 28 28 28 27 28 819730903 755946410 28 28 29 792662140 891539003 583799124 817190966 934413263 29 29 865467960 28 29 29 488557236 28 28 618111955 29 28 8328741...
result:
wrong answer 2nd numbers differ - expected: '28', found: '29'