QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639436 | #8548. China Convex Polygon Contest | argtarg | WA | 18ms | 3792kb | C++20 | 2.0kb | 2024-10-13 19:34:35 | 2024-10-13 19:34:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pii pair<int, int>
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--)solve();
return 0;
}
//const int mod = 998244353;
void solve() {
int n;
int m;
cin>>n>>m;
vector<int>a(n+1),b(n+2);
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
b[n+1]=1e18;
// sort(b.begin()+1,b.end());
a.push_back(b[1]);
// for(int i=1;i<=n;i++)if(b[i]<=m)a.push_back(b[i]);
sort(a.begin()+1,a.end());
for(int i=1;i<=n;i++){
b[i]+=b[i-1];
// cout<<"b== ";cout<<b[i]<<endl;;
}
priority_queue<int,vector<int>,greater<int>>q1,q2;
for(int i=1;i<=n;i++){
if(b[i]>m)break;
auto it= lower_bound(a.begin()+1,a.end(),b[i]);
while(it!=a.end()&&(*it)<min(m+1,b[i+1])){
int x=*it;
int y=m;
it++;
if(it!=a.end())y=*it;
// cout<<"i== "<<i<<' ';
// cout<<"===="<<x<<endl;
if(1)q2.push(y-x);
else q1.push(y-x);
}
auto t= lower_bound(a.begin()+1,a.end(),b[i]+1);
int x=b[i];
while(t!=a.end()&&(*t)<=min(m+1,b[i+1])){
int y=m;
y=*t;
if(1)q1.push(y-x);
x=y;
t++;
}
while(q2.size()>i){
q2.pop();
}
while(q1.size()>i){
q1.pop();
}
}
int ans=0;
int sum=0;
while(q1.size()){
sum+=q1.top();
q1.pop();
ans=sum;
}
sum=0;
while(q2.size()){
// cout<<"---"<<q2.top()<<endl;
sum+=q2.top();
q2.pop();
ans=max(ans,sum);
}
cout<<ans<<endl;
}
/*
2
3 13
6 7 13
1 9 999
4 14
6 7 13 14
1 9 999 999
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 18ms
memory: 3792kb
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:
729337914 26 23 508883916 28 820816836 25 769874714 942603170 588072505 492186961 454332137 24 27 26 703954964 18 25 26 608247897 24 23 26 26 25 28 27 27 24 680432876 655486509 24 26 23 710720807 728746368 511610245 678803216 909314391 26 28 813993374 25 23 29 429433659 21 22 504593826 21 22 7111523...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '729337914'