QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697417#9528. New Energy VehiclewirepullerRE 0ms3524kbC++141.7kb2024-11-01 13:58:492024-11-01 13:58:49

Judging History

This is the latest submission verdict.

  • [2024-11-01 13:58:49]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3524kb
  • [2024-11-01 13:58:49]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define mp make_pair
#define endl '\n'
#define dbug() cout << '||||||debug|||||' << endl;
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
const int N = 1e5+10;
const int mod = 1e9+7;
const int INF = 1e18;
void solve()
{
    int n, m, k;
    cin >> n >> m;
    vi a(n+1), c(n+1), x(m+1), t(m+1), fir(n+1), lst(n+1), nxt(n+1);
    fo(i,1,n) cin >> a[i], c[i] = a[i];
    fo(i,1,m) cin >> x[i] >> t[i];
    fo(i,1,n) fir[i] = m+1, lst[i] = 0;
    fo(i,1,m){
        if (fir[t[i]] > m) fir[t[i]] = i;
        if (lst[t[i]]) nxt[lst[t[i]]] = i;
        lst[t[i]] = i;
    }
    for (int i = 1; i<=n; i++) if (lst[i]) nxt[lst[i]] = m+1;
    set<pair<int, int>> s;
    for (int i = 1; i<=n; i++) s.insert(pair<int, int>(fir[i], i));
    int sum = 0;
    for (int i = 1; i<=m; i++){
        int r = x[i]-x[i-1];
        while (!s.empty() && c[s.begin()->second] <= r){
            int k = s.begin()->second;
            sum += c[k];
            r -= c[k];
            c[k]=0;
            s.erase(s.begin());
        }
        if (s.empty() && r > 0) {
            cout << sum << endl;
            return ;
        }
        c[s.begin()->second] -= r;
        sum += r;
        c[t[i]] = a[t[i]];
        if (s.find(pair<int, int>(i, t[i]))!= s.end()) s.erase(pair<int, int>(i, t[i]));
        s.insert(pair<int, int>(nxt[i], t[i]));
    }
    for (int i = 1; i<=n; i++) sum += c[i];
    cout << sum << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    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: 3524kb

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: