QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716779#9528. New Energy Vehicleobiwan114RE 0ms3540kbC++201.3kb2024-11-06 16:01:422024-11-06 16:01:45

Judging History

This is the latest submission verdict.

  • [2024-11-06 16:01:45]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3540kb
  • [2024-11-06 16:01:42]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;
//#define int long long
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MAXX = 2e5 + 10;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
void solve() {
    int n,m;
    cin >> n >> m;
    vector<ll>a(n + 5);
    vector<ll>b(n + 5);
    vector<ll>x(m + 5);
    vector<ll>t(m + 5);
    vector<ll>nx(m + 5);
    vector<int>h(n + 5,m + 1);
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    for(int i = 1;i <= m;i++){
        cin >> x[i] >> t[i];
    }
//    x[m + 1] = INF;
    for(int i = m;i >= 1;i--){
        nx[i] = h[x[i]];
        h[x[i]] = i;
    }
    priority_queue<pll,vector<pll>,greater<>>q;
    for(int i = 1;i <= n;i++){
        q.push({h[i],i});
    }
    int l = 1;
    ll ans = 0;
    while(!q.empty()){
        auto [w,u] = q.top();
        if(x[l] - ans > b[u]){
            ans += b[u];
            b[u] = 0;
            q.pop();
        }else{
            b[u] -= x[l] - ans;
            ans = x[l];
            if(t[l] == u || b[u] == 0)q.pop();
            b[t[l]] = a[t[l]];
            q.push({nx[t[l]],t[l]});
            l++;
        }
    }
    cout << ans << "\n";
}

signed main() {
    int t = 1;
    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: 3540kb

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:

9
9
4
9

result: