QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672433 | #8548. China Convex Polygon Contest | libantian# | WA | 22ms | 3816kb | C++23 | 1.8kb | 2024-10-24 16:48:37 | 2024-10-24 16:48:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define all(_a) _a.begin(), _a.end()
void solve(){
int n,m;
cin>>n>>m;
vector<int>a;
vector<int>b(n+1);
for(int i=1;i<=n;i++)cin>>b[i];
for(int i=1;i<=n;i++){
int x;
cin>>x;
a.push_back(x);
}
sort(all(a));
for(int i=1;i<n;i++)a[i]+=a[i-1];
priority_queue<int>q;
int res=0;
for(int i=n;i>=1;i--){
int cnt=0;
int mi=m;
while(a.size()&&a.back()>=b[i]){
cnt++;
mi=min(mi,a.back());
a.pop_back();
}
//cout<<cnt<<endl;
if(cnt==0){
if(i==n)q.push(m-b[i]);
else q.push(m-b[i]);
m=b[i];
continue;
}
while(cnt>=2&&q.size()){
cnt--;
res+=q.top();
q.pop();
}
if(q.size()==0){
res+=m-mi;
q.push(mi-b[i]);
m=b[i];
}else{
if(m-mi>q.top()){
res+=m-mi;
auto t=q.top();
q.pop();
t+=mi-b[i];
q.push(t);
m=b[i];
}else{
res+=q.top();
q.pop();
q.push(m-b[i]);
m=b[i];
}
}
//cout<<res<<endl;
}
cout<<res<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cout << setiosflags(ios::fixed) << setprecision(15);
int T;
T=1;
cin>>T;
while(T--)solve();
return 0;
}
詳細信息
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: 22ms
memory: 3816kb
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:
683472444 19 20 508883916 28 875933380 19 778674670 479667739 720683076 373267145 728798776 27 26 28 455838261 19 17 11 604107903 22 23 29 26 28 16 20 26 27 791428625 741603286 27 24 28 492282312 868779973 118657929 500364054 442706433 21 21 627608307 26 18 29 399824254 21 24 496116457 28 12 8002157...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '683472444'