QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722610#9528. New Energy VehiclexixixiWA 1ms5872kbC++141.9kb2024-11-07 19:38:552024-11-07 19:38:56

Judging History

This is the latest submission verdict.

  • [2024-11-07 19:38:56]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5872kb
  • [2024-11-07 19:38:55]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxn=1e5+7,mxm=5e5+7;;
int n,m,a[mxn],x[mxn],t[mxn],c[mxn];
int T,vis[mxn];
struct ST{
    int dis,id;
    bool operator<(const ST& other)const{
        if(c[id]==0) return true;
        return dis>other.dis;
    }
};

signed main(){   
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> T;
    while(T--){
        priority_queue<ST>q;
        cin >> n >> m;
        for(int i=1;i<=n;i++)
            cin>>a[i],c[i]=a[i],vis[i]=0;

        for(int i=1;i<=m;i++){
            cin >> x[i] >> t[i];
            q.push({x[i],t[i]});
            vis[t[i]]+=1;
        }

        int tmp=0;
        for(int i=1;i<=n;i++)if(!vis[i]) tmp+=a[i];

        int now=0,ans=0,fg=1;
        while(!q.empty()){
            
            int to=q.top().dis;
            int y=q.top().id;

            while(now<to){
                int x=q.top().id;
                if(c[x]==0){
                    int dx=min(tmp,to-now);
                    now+=dx;
                    tmp-=dx;
                    break;
                }


                while(q.size()&&q.top().dis<now){
                    vis[q.top().id]--;
                    if(vis[q.top().id]==0)tmp+=c[q.top().id];
                    q.pop();
                    }

                int dx=min(to-now,c[x]);
                c[x]-=dx;
                // if(c[x]==0) in[x]=0;
                now+=dx;
            }

            if(now<to)break;
            c[y]=a[y];
            while(q.size()&&q.top().dis<now){
                {
                    vis[q.top().id]--;
                    if(vis[q.top().id]==0)tmp+=c[q.top().id];
                    q.pop();
                    }
            }
            q.pop();vis[y]--;
            if(vis[y]==0) tmp+=c[y];
        }

        now+=tmp;
        cout<<now<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5868kb

input:

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

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5872kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
2
11
999999999
2000000000

result:

wrong answer 3rd lines differ - expected: '4', found: '2'