QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682971#9528. New Energy Vehiclefgz#WA 0ms3800kbC++231.8kb2024-10-27 18:11:432024-10-27 18:11:44

Judging History

This is the latest submission verdict.

  • [2024-10-27 18:11:44]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3800kb
  • [2024-10-27 18:11:43]
  • Submitted

answer

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0), cin.tie(0)
#define time chrono::system_clock::now().time_since_epoch().count()
using namespace std;
#define int long long
using ll = long long;
using pll = pair<int, int>;

const int mod = 1e9 + 7, N = 2e5 + 10;

void solve(){
    int n, m; cin >> n >> m;
    vector<int> a(n + 10), st(n + 10);
    for (int i = 1; i <= n; i ++) cin >> a[i], st[i] = a[i];
    vector<pll> b(m + n + 10);
    vector<int> nx(n + m + 10);
    for (int i = 1; i <= m; i ++) {
        cin >> b[i].first >> b[i].second;
    }
    for (int i = 1; i <= n; i ++) {
        b[m + i] = {1e18, i};
    }
    vector<int> mp(n + 10, n + m + 10);
    for (int i = n + m; i >= 1; i --) {
        nx[i] = mp[b[i].second];
        mp[b[i].second] = i;
    }

    multiset<pll> s;
    for (int i = 1, j = 1; i <= n + m; i ++) {
        int dis = b[i].first - b[i - 1].first;
        while (j < i) j ++;
        while (s.size() && dis) {
            auto [id, v] = *s.begin();
            s.erase(s.find({id, v}));
            if (id < i) continue;
            int t = min(dis, v);
            dis -= t;
            a[id] -= t;
            if (v - t > 0) s.insert({id, v - t});
        }
        while(dis && j <= n + m) {
            int t = min(a[b[j].second], dis);
            dis -= t;
            a[b[j].second] -= t;
            j ++;
        }
        if (dis == 0) j --;
        if (dis) {
            int t = b[i].first - dis;
            cout << t << '\n';
            return;
        }
        a[b[i].second] = st[b[i].second];
        if (nx[i] > j) continue;
        else {
            s.insert({nx[i], a[b[i].second]});
        }
    }
}

signed main()
{
    ios;
    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: 3800kb

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

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:

6
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '6'