QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252970#7622. Yet Another CoffeeGeospiza#WA 0ms3784kbC++201.9kb2023-11-16 15:59:522023-11-16 15:59:52

Judging History

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

  • [2023-11-16 15:59:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2023-11-16 15:59:52]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int	main(){
    ios::sync_with_stdio(0); cin.tie(0);
	int T=1;
	cin>>T;
	while(T--)
    {
        ll n,m;
        cin>>n>>m;
        vector<ll>a(n+5);
        ll sum=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        vector<ll>r(m+5),w(m+5);
        vector<ll>pre(n+5),ans(n+5),vis(n+5,1);
        for(int i=1;i<=m;i++){
            cin>>r[i]>>w[i];
            pre[r[i]]+=w[i];
            sum-=w[i];
        }
        //cout<<sum<<"\n";
        for(int i=1;i<=n;i++){
            pre[i]+=pre[i-1];
        }

        priority_queue<pll>q;
        for(int i=1;i<=n;i++){
            q.push({a[i],i});
        }

        ans[n]=sum;
        ll mex=1;
        for(int i=n-1;i>=1;i--){
            while(vis[mex]==0){
                mex++;
            }
            auto [x,id1]=q.top();q.pop();
            //if(i==2){ cout<<mex<<" "<<x<<" "<<id1<<"\n"; }
            if(id1==mex){
                auto [y,id2]=q.top();q.pop();
                if(x-pre[id1]>=y){
                    ans[i]=sum-(x-pre[id1]);
                    sum-=x;
                    q.push({y,id2});
                    vis[id1]=0;
                }
                else{
                    sum-=y;
                    ans[i]=sum;
                    q.push({x,id1});
                    vis[id2]=0;
                }
            }
            else{
                sum-=x;
                ans[i]=sum;
                vis[id1]=0;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<ans[i]<<" ";
        }
        cout<<"\n";
    }
}
/*
2
 5 2
 1 2 3 4 5
 3 1
 4 2
 7 3
 4 3 1 10 3 8 6
 4 9
 3 8
 4 5

1
5 2
3 5 2 1 1
2 2
3 1

1
6 3
9 14 12 1 5 4
4 3
2 5
1 9


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3784kb

input:

5
10 14
17 37 59 65 53 73 68 177 160 111
10 177
5 193
2 30
3 63
2 339
3 263
5 178
2 190
9 23
10 328
10 200
9 8
3 391
6 230
12 9
152 306 86 88 324 59 18 14 42 260 304 55
3 50
2 170
1 252
7 811
1 713
7 215
10 201
4 926
8 319
19 20
182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...

output:

-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 
-3505 -3491 -3473 -3431 -3376 -3317 -3231 -3143 -2883 -2579 -2273 -1949 
-6527 -6496 -6448 -6374 -6258 -6092 -5922 -5743 -5563 -5368 -5167 -4934 -4691 -4428 -4156 -3875 -3591 -3272 -2946 
-3242 -2987 -2572 -2140 -1707 -1238 -768 -274 243 1...

result:

wrong answer 42nd numbers differ - expected: '-3219', found: '-3242'