QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707144#9528. New Energy Vehiclewjynb666WA 0ms3748kbC++141.5kb2024-11-03 14:50:012024-11-03 14:50:02

Judging History

This is the latest submission verdict.

  • [2024-11-03 14:50:02]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3748kb
  • [2024-11-03 14:50:01]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define  read_fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using ll=long  long;
struct cmp{
    bool operator()(pair<int,int> a,pair<int,int> b){
        if(a.first!=b.first)return a.first>b.first;
        return a.second<b.second;
    }
};
void solve(){
    int n,m;
    cin>>n>>m;
    //先写一个O(n^2)的贪心
    vector<int> a(n);
    vector<int> s(a);
    for(int i=0;i<n;i++) cin>>a[i],s[i]=a[i];
    vector<array<int,2>> b(m);
    priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
    vector<int> st(n);
    for(int i=0;i<m;i++) cin>>b[i][0]>>b[i][1],b[i][1]--,q.push({b[i][0],b[i][1]}),st[b[i][1]]=1;
    sort(b.begin(),b.end());
    for(int i=0;i<n;i++)
        if(!st[i])
            q.push({1e9+5,i});
    
    ll ans=0;
    int last=0;
    for(int i=0;i<m;i++){
        //依次去使用,后面的内容
        int need=b[i][0]-last;
        vector<pair<int,int>> tmp;
        while(!q.empty()){
            auto t=q.top();
            q.pop();
            tmp.push_back(t);
            int res=min(need,a[t.second]);
            a[t.second]-=res;
            need-=res;
            ans+=res;
            if(need==0) break;
        }
        for(auto x:tmp) q.push(x);
        q.pop();
        a[b[i][1]]=s[b[i][1]];
        last=b[i][0];
    }
    
    for(int i=0;i<n;i++){
        if(a[i]>0) ans+=a[i];
    }
    cout<<ans<<'\n';
}


int main()
{
    read_fast;
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3600kb

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
10
11
1999999998
2000000000

result:

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