QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548969#7523. Partially Free MealHannnaWA 139ms23572kbC++142.0kb2024-09-05 22:33:042024-09-05 22:33:05

Judging History

你现在查看的是最新测评结果

  • [2024-09-05 22:33:05]
  • 评测
  • 测评结果:WA
  • 用时:139ms
  • 内存:23572kb
  • [2024-09-05 22:33:04]
  • 提交

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];
struct PII{
    int a,id;
    bool operator<(const PII &e)const{
        if(a==e.a) return pb[id]<pb[e.id];
        return a>e.a;
    }
};
bool st[N],vis[N];
void solve()
{
    cin>>n;
    priority_queue<PII >p1;
    priority_queue<PII >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().id;
            if(st[id]) {
                //p2.push({-pa[id],id});
                p1.pop();
            }//该数b小于maxb,实际贡献在p2中
            else if(vis[id]) p1.pop();
            else {
                t1=(p1.top().a)-maxb;
                id1=id;
                //maxt=max(pb[id],maxt);
                //p1.pop();
                break;
            }
        }
        while(!p2.empty()){
            int id=p2.top().id;
            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: 5584kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 139ms
memory: 23572kb

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'