QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#611834 | #8548. China Convex Polygon Contest | ucup-team3651 | WA | 9ms | 5636kb | C++20 | 2.0kb | 2024-10-04 23:08:53 | 2024-10-04 23:08:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define IL inline
#define mod 998244353
#define N 300005
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
void write(ll x){
if(x<0)x=-x,putchar('-');
if(x/10)write(x/10);
putchar(x%10+'0');
}
ll a[N],b[N];
priority_queue<ll,vector<ll>,greater<ll> > q;
void solve(){
while(q.size())q.pop();
ll n=read(),m=read();
for(ll i=1;i<=n;i++)a[i]=read();
for(ll i=1;i<=n;i++)b[i]=read();
sort(b+1,b+n+1);
for(ll i=1;i<=n;i++)b[i]+=b[i-1];
ll pos=n+1,res=0;
while(pos-1!=0 && b[pos-1]>m)pos--;
a[n+1]=m;
for(ll i=n;i>=0;i--){
vi S;
while(pos-1!=0 && b[pos-1]>=a[i])pos--,S.pb(b[pos]);
if(!S.size()){
q.push(a[i+1]-a[i]);continue;
}
reverse(S.begin(),S.end());
for(ll i=S.size()-1;i>=1;i--){
ll v=S[i];
if(q.size())res+=q.top(),q.pop();
}
//cerr<<i<<' '<<q.size()<<' '<<res<<' '<<a[i+1]<<' '<<S[0]<<endl;
if(q.size() && q.top()>a[i+1]-S[0]){
res+=q.top();q.pop();q.push(a[i+1]-a[i]);
}
else{
ll opt=S[0]-a[i];
if(q.size())opt+=q.top(),q.pop();
res+=a[i+1]-S[0];q.push(opt);
}
}
//cerr<<endl;
write(res);putchar('\n');
}
int main(){
#ifdef EAST_CLOUD
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
ll T=read();while(T--)solve();
return 0;
}
//cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
//cerr<<"\n"<<clock()*1.0/CLOCKS_PER_SEC*1000<<"ms\n";
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5624kb
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: 9ms
memory: 5636kb
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:
754749634 26 22 548785306 28 865635076 22 796209714 866488449 720683076 355392761 579792782 24 25 28 770944032 21 26 25 711205025 25 24 26 28 28 26 26 27 28 819730903 755946410 28 21 28 573609773 891539003 477382729 718034902 760308196 26 24 677168302 24 23 25 483836554 20 22 435376844 28 20 6812271...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '754749634'