QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548949 | #7523. Partially Free Meal | Hannna | WA | 120ms | 22340kb | C++14 | 1.9kb | 2024-09-05 22:17:41 | 2024-09-05 22:17:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n;
int pa[N],pb[N];
struct node{
int a,b,id;
bool operator<(const node &e)const {
if(b==e.b) return a<e.a;
return b<e.b;
}
}p[N];
bool st[N],vis[N];
void solve()
{
cin>>n;
priority_queue<pair<int,int> >p1;
priority_queue<pair<int,int> >p2;
for(int i=1;i<=n;i++){
cin>>p[i].a>>p[i].b;
pa[i]=p[i].a,pb[i]=p[i].b;
p1.push({-(p[i].a+p[i].b),i});
p[i].id=i;
}
sort(p+1,p+1+n);
int maxb=0,ans=0,pp=1;
for(int i=1;i<=n;i++){
int t1=2e9+5,t2=t1,maxt=0,id1,id2;
while(!p1.empty()){
int id=p1.top().second;
if(st[id]) {
//p2.push({-pa[id],id});
p1.pop();
}//该数b小于maxb,实际贡献在p2中
else if(vis[id]) p1.pop();
else {
t1=-(p1.top().first)-maxb;
id1=id;
//maxt=max(pb[id],maxt);
//p1.pop();
break;
}
}
while(!p2.empty()){
int id=p2.top().second;
if(vis[id]) {
p2.pop();
continue;
}
t2=pa[id];
id2=id;
//p2.pop();
break;
}
if(t1<=t2){
ans+=t1;
maxb=max(pb[id1],maxb);
vis[id1]=1;
p1.pop();
}
else ans+=t2,vis[id2]=1,p2.pop();
//cout<<t1<<" "<<t2<<endl;
cout<<ans<<endl;
while(pp<=n&&p[pp].b<maxb) {
if(!vis[p[pp].id])
p2.push({-p[pp].a,p[pp].id});
st[p[pp].id]=1;
pp++;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T=1;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7664kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 120ms
memory: 22340kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
1318594 3208018 5570526 7340845 9223347 11487338 13751811 16532451 17560831 19309829 21108821 22990148 24475695 25467968 26430542 27815157 29410889 30978895 32666076 34583473 36594398 37596721 38636691 40422322 42408932 44248691 46082393 47916747 49838235 52476909 55158583 58072674 61026526 64003437...
result:
wrong answer 6th lines differ - expected: '11149865', found: '11487338'