QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696706#9528. New Energy Vehiclejnmrtnz111WA 76ms69460kbC++202.7kb2024-11-01 00:38:382024-11-01 00:38:39

Judging History

This is the latest submission verdict.

  • [2024-11-01 00:38:39]
  • Judged
  • Verdict: WA
  • Time: 76ms
  • Memory: 69460kb
  • [2024-11-01 00:38:38]
  • Submitted

answer

#include<bits/stdc++.h>
#define forn(u,n) for(int u=0;u<n;++u)
#define forns(u,i,n) for(int u=i;u<n;++u)
#define reverso
#define pb push_back
#define all(a) a.begin(), a.end()
#define snd second
#define fst first

using namespace std;

typedef long long ll;
int main(){
    #ifdef LOCAL
        freopen("entra.in","r",stdin);
    #endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        queue<ll>place[n+2];//PARA CADA BATERIA TIENE ORDENADO DISTANCIA DE LA MAS CERCANA
        vector<ll>battery(n+1,0);//ACTUALMENTE PARA DEL TIPO I HAY battery_i
        vector<ll>tope(n+1,0);//ACTUALMENTE PARA DEL TIPO I HAY battery_i
        forns(i,1,n+1){
            cin>>battery[i];
            tope[i]=battery[i];
        }
        vector<pair<ll,ll>>charge;//ORDENA LA GASOLINERAS
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>>prioridad; // DE CUAL BATERIA TOMAR
        forn(i,m){
            ll x;
            int type;
            cin>>x>>type;
            charge.pb({x,type});
        }
        sort(all(charge));
        for(auto it:charge){
            place[it.snd].push(it.fst);
        }
        forns(i,1,n+1){
            if(place[i].size()){
                prioridad.push({place[i].front(),i});
                place[i].pop();
            }
            else{
                prioridad.push({INT_MAX,i});
            }
        }
        ll cur=0;//POSICIÓN ACTUAL
        int indx=0;//posición gasolinera
        charge.pb({LLONG_MAX,1});
        for(auto it:charge){
        }
        for(int i=0;i<charge.size();i++){
            pair<ll , ll >gasAct=charge[i];
            while(cur<gasAct.first and prioridad.size()){
                ll batAct=prioridad.top().second;
                if(cur+battery[batAct]>gasAct.first){
                    ll dif=gasAct.first-cur;
//                    cout<<dif<<" -"<<"\n";
                    battery[batAct]-=dif;
                    cur=gasAct.first;
                }
                else{
                    cur+=battery[batAct];
                    battery[batAct]=0;
                    prioridad.pop();
                }
            }
            if(cur<gasAct.first)break;
            battery[gasAct.second]=tope[gasAct.second];
            int indx=gasAct.second;
            if(place[indx].size())place[indx].pop();
            if(place[indx].size()){
                prioridad.push({place[indx].front(),indx});
            }
            else{
                prioridad.push({INT_MAX,indx});
            }
            while(prioridad.size() and prioridad.top().first<=cur)prioridad.pop();
        }
        cout<<cur<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3860kb

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

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 76ms
memory: 69460kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1543020
1578939
1521240
1527381
1547404
1564631
1011701
1548178
1038710
1011599

result:

wrong answer 3rd lines differ - expected: '1526016', found: '1521240'