QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685656#9528. New Energy Vehicleyxd#RE 0ms0kbC++141.4kb2024-10-28 20:39:322024-10-28 20:39:33

Judging History

This is the latest submission verdict.

  • [2024-10-28 20:39:33]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-28 20:39:32]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
pair<int,int> a[N];
int b[N],c[N];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n,m;
        cin>>n>>m;

        for(int i=1;i<=n;i++){
            cin>>b[i];
            c[i]=b[i];
        }
        for(int i=1;i<=m;i++){
            cin>>a[i].first>>a[i].second;
        }
        sort(a+1,a+m+1);

        int res=0,pre=1,idx=0;
        for(int i=1;i<=m;i++){
            if(a[i].first>b[a[i].second]){
                res+=b[a[i].second];
                idx+=b[a[i].second];
                b[a[i].second]=0;
            }else{
                res+=a[i].first-idx;
                idx=a[i].first;
            }
            while(idx>=a[pre].first){
                b[a[pre].second]=c[a[pre].second];
                pre++;
            }
        }
        for(int i=1;i<=n;i++){
            if(b[i]){
                idx+=b[i];
            }else{
                continue;
            }
            while(idx>=a[pre].first){
                b[a[pre].second]=c[a[pre].second];
                pre++;
                if(pre>m)break;
            }
        }
        for(int i=1;i<=n;i++){
            res+=b[i];
        }
        cout<<res<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: