QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690253#9528. New Energy VehicleYYCQAQ#WA 1ms7688kbC++201.5kb2024-10-30 21:16:022024-10-30 21:16:08

Judging History

This is the latest submission verdict.

  • [2024-10-30 21:16:08]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7688kb
  • [2024-10-30 21:16:02]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const ll N=1e5+10;
const ll INF=1e18+10;
ll n,m;
ll a[N],x[N],t[N];
ll now[N];
vector<ll>charge[N];
ll pt[N];
void solve(){
    cin>>n>>m;
    for(ll i=1;i<=n;++i){
        a[i]=now[i]=0;
        charge[i].clear();
        pt[i]=0;
    }
    for(ll i=1;i<=n;++i){
        cin>>a[i];
        now[i]=a[i];
    }
    for(ll i=1;i<=m;++i){
        cin>>x[i]>>t[i];
        charge[t[i]].push_back(x[i]);
    }
    ll ans=0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>q;
    for(ll i=1;i<=n;++i){
        if(charge[i].size())q.push({x[0],i});
        else q.push({INF,i});
    }
    // for(ll i=1;i<=m;++i){
    //     q.push({x[i],t[i]});
    // }
    for(ll i=1;i<=m;++i){
        while(x[i]>ans&&q.size()){
            pair<ll,ll>p=q.top();q.pop();
            ll tmp=min(x[i]-ans,now[p.second]);
            now[p.second]-=tmp;
            ans+=tmp;
            if(now[p.second])q.push(p);
        }
        if(ans<x[i])break;
        now[t[i]]=a[i];
        pt[t[i]]++;
        if(pt[t[i]]<charge[t[i]].size()){
            q.push({charge[t[i]][pt[t[i]]],t[i]});
        }else {
            q.push({INF,t[i]});
        }
    }
    for(ll i=1;i<=n;++i)ans+=now[i];
    cout<<ans<<endl;


}
signed main(void){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll Times=1;
    cin>>Times;
    while(Times--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5672kb

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: 0ms
memory: 7688kb

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
9
4
9
999999999
2000000000

result:

wrong answer 2nd lines differ - expected: '11', found: '9'