QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#683384#9528. New Energy Vehicleivyoruska#WA 0ms3604kbC++201.9kb2024-10-27 20:40:112024-10-27 20:40:12

Judging History

This is the latest submission verdict.

  • [2024-10-27 20:40:12]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3604kb
  • [2024-10-27 20:40:11]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

struct station {
    int x, t;
    bool operator<(const station &p) const {
        return x > p.x;
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> cap(n + 1);
    vector<int> pcap(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> cap[i];
        pcap[i] = cap[i];
    }
    vector<pair<int, int> > sta(m);
    for (int i = 0; i < m; i++) {
        int x, t;
        cin >> x >> t;
        sta[i] = {x, t};
    }
    sort(sta.begin(), sta.end());

    vector<vector<int> > t(n + 1);
    vector<int> pt(n + 1, 0);
    for (auto [x, tt] : sta) t[tt].emplace_back(x);

    priority_queue<station> pq;
    i64 capl = 0;
    for (int i = 1; i <= n; i++) {
        if (t[i].size()) {
            pq.push({t[i][0], i});
            pt[i]++;
        } else
            capl += cap[i];
    }

    i64 px = 0;
    for (int i = 0; i < m; i++) {
        auto [x, idx] = sta[i];
        while (pq.size() && pcap[pq.top().t] <= x - px) {
            px += pcap[pq.top().t];
            cerr << px << '\n';
            pcap[pq.top().t] = 0;
            pq.pop();
        }
        //cerr << px << '\n';

        if (pq.size()) {
            pcap[pq.top().t] -= (x - px);
            px = x;
        } else {
            if (capl >= (x - px)) {
                capl -= (x - px);
                px = x;
            } else {
                px += capl;
                cout << px << '\n';
                return;
            }
        }

        pcap[idx] = cap[idx];
        if (pt[idx] < t[idx].size()) {
            pq.push({t[idx][pt[idx]], idx});
            pt[idx]++;
        } else {
            capl += cap[idx];
        }
    }

    cout << px + capl << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int _;
    cin >> _;
    while (_--) solve();

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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

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

result:

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