QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#681267#9528. New Energy Vehicleucup-team1134#RE 1ms3620kbC++232.8kb2024-10-27 03:56:252024-10-27 03:56:26

Judging History

This is the latest submission verdict.

  • [2024-10-27 03:56:26]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3620kb
  • [2024-10-27 03:56:25]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=100005;
const ll INF=15LL<<58;

vi wh[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        ll N,M;cin>>N>>M;
        for(int i=0;i<N;i++){
            wh[i].clear();
        }
        vl A(N),B(N);
        for(int i=0;i<N;i++){
            cin>>A[i];
        }
        B=A;
        vl len={0};
        vi tp(M);
        for(int i=0;i<M;i++){
            ll x,t;cin>>x>>t;t--;
            wh[t].pb(i);
            len.pb(x);
            tp[i]=t;
        }
        len.pb(INF);
        for(int i=si(len)-1;i>=1;i--){
            len[i]-=len[i-1];
        }
        len.erase(len.begin());
        for(int i=0;i<N;i++){
            wh[i].pb(M);
            reverse(all(wh[i]));
        }
        
        priority_queue<array<ll,3>> PQ;
        
        for(int i=0;i<N;i++){
            PQ.push({-wh[i].back(),B[i],i});
        }
        
        ll ans=0;
        
        for(int ii=0;ii<si(len);ii++){
            ll rem=len[ii];
            while(rem){
                if(si(PQ)==0) break;
                auto [t,h,i]=PQ.top();PQ.pop();
                t*=-1;
                ll can=min(h,rem);
                ans+=can;
                if(can==h){
                    rem-=can;
                    B[i]=0;
                }else{
                    rem-=can;
                    B[i]-=can;
                    PQ.push({-t,B[i],i});
                }
            }
            
            if(rem) break;
            
            int i=tp[ii];
            
            if(PQ.top()[2]==i){
                PQ.pop();
                B[i]=A[i];
                wh[i].pop_back();
                PQ.push({-wh[i].back(),B[i],i});
            }else{
                B[i]=A[i];
                wh[i].pop_back();
                PQ.push({-wh[i].back(),B[i],i});
            }
        }
        
        cout<<ans<<"\n";
    }
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Runtime Error

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:


result: