QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#709925#9528. New Energy Vehicleghosh__#WA 17ms73572kbC++231.6kb2024-11-04 17:28:022024-11-04 17:28:03

Judging History

This is the latest submission verdict.

  • [2024-11-04 17:28:03]
  • Judged
  • Verdict: WA
  • Time: 17ms
  • Memory: 73572kb
  • [2024-11-04 17:28:02]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define int long long
const int maxn = 1e5 + 5;
int n, m, a[maxn], x[maxn], t[maxn], b[maxn];
queue<int> q[maxn];
void Solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) while (q[i].size()) q[i].pop();
    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];
        q[t[i]].push(x[i]);
    }
    int cur = 0;
    set<pair<int,int>> s;
    for (int i = 1; i <= n; i++) {
        if (q[i].size()) {
            s.insert({q[i].front(), i});
            q[i].pop();
        }
        else {
            s.insert({2e9, i});
        }
    }
    int now = 0;
    while (now < m) {
        int res = x[now + 1] - cur;
        while (res) {
            if (s.empty()) break;
            int id = s.begin() -> second;
            int val = min(res, a[id]);
            res -= val;
            a[id] -= val;
            cur += val;
            if (!a[id]) s.erase(s.begin());
        }
        if (res) break;
        now++;
        a[t[now]] = b[t[now]];
        int col = t[now];
        if (s.find({x[now], t[now]}) != s.end()) s.erase({x[now], t[now]});
        if (q[col].size()) {
            s.insert({q[col].front(), col});
            q[col].pop();
        }
    }
    for (int i = 1; i <= n; i++) cur += a[i];
    cout << cur << endl;
}
signed main() {
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    int T;
    cin >> T;
    while (T--){
        Solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 17ms
memory: 72500kb

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: 3ms
memory: 73572kb

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

result:

wrong answer 2nd lines differ - expected: '11', found: '8'