QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679059#9528. New Energy Vehicleucup-team4975#WA 0ms3588kbC++232.2kb2024-10-26 16:46:412024-10-26 16:46:49

Judging History

This is the latest submission verdict.

  • [2024-10-26 16:46:49]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3588kb
  • [2024-10-26 16:46:41]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
#define el '\n'
using namespace std;
using ll = long long;
using PII = pair<int, int>;
void solve() 
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1, 0), t(m + 1, 0);
    vector<int> now(n + 1, 0), p(m + 1, 0);
    for (int i =1 ;i <= n; i++) {
        cin >> a[i];
    }
    now = a;
    vector<vector<int>> pl(n + 1);
    vector<int> tmp(n + 1);
    for (int i = 1;i <= m; i++) {
        int x;
        cin >> x >> t[i];
        p[i] = x;
        pl[t[i]].push_back(x);
    }
    set<PII> q;
    for (int i = 1; i <= n ;i++) {
        if (pl[i].size() == 0)
            q.insert(PII(2e9, i));
        else {
            q.insert(PII(pl[i][0], i));
        }
        pl[i].push_back(2e9);
    }

    // for (int i = 1; i <= n; i++) {
    //     cout << i << endl;
    //     for (auto x : pl[i]) {
    //         cout << x << " ";
    //     }
    //     cout << endl;
    // }

    ll ans = 0;
    for (int i = 1; i <= m; i++) {
        int x = p[i] - p[i - 1];
        while (x && !q.empty()) {
            auto [plp, col] = *q.begin();
            // cout << i << " " << plp << " " << col << endl;
            q.erase(q.begin());
            int lft = min(now[col], x);
            now[col] -= lft;
            x -= lft;
            ans += lft;
            if (now[col] != 0) {
                q.insert(PII(plp, col));
            }
        }
        int nowcol = t[i];
        if (q.find(PII(p[i], t[i])) != q.end()) {
            assert(now[t[i]] > 0);
            q.erase(q.find(PII(p[i], t[i])));
        }
        else 
            assert(now[t[i]] == 0);
        tmp[nowcol]++;
        now[nowcol] = a[nowcol];
        // cout << i << " " << nowcol << endl;
        q.insert(PII(pl[nowcol][tmp[nowcol]], nowcol));
        // cout << "add "  << pl[nowcol][tmp[nowcol]] << " " << nowcol << endl;
    }
    for (int i = 1; i <= n; i++){
        ans += now[i];
    }
    cout << ans << el;
}   
signed main() 
{
    ios:: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    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: 3588kb

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

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
10
11
1999999998
2000000000

result:

wrong answer 3rd lines differ - expected: '4', found: '10'