QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#700087#9528. New Energy Vehiclefoolnine#WA 0ms3872kbC++201.2kb2024-11-02 11:56:022024-11-02 11:56:02

Judging History

This is the latest submission verdict.

  • [2024-11-02 11:56:02]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3872kb
  • [2024-11-02 11:56:02]
  • Submitted

answer

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

using i64 = long long;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<i64> a(n), b(m + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[0] += a[i];
    }

    vector<int> x(m + 1), t(m + 1), free(m + 1, 0);
    for (int i = 1; i <= m; i++) {
        cin >> x[i] >> t[i];
        t[i]--;
    }

    i64 ans = 0;
    for (int i = 1; i <= m; i++) {
        i64 cost = x[i] - x[i - 1];
        if (b[i - 1] < cost) {
            ans = x[i - 1] + b[i - 1];
            break;
        } else {
            i64 cal = cost + free[i - 1], can = a[t[i]];
            if (cal >= can) {
                b[i] = b[i - 1] - cost + can;
                free[i] = cal - can;
            } else {
                b[i] = b[i - 1] - cost + cal;
                free[i] = 0;
            }

            if (i == m) {
                ans = x[i] + b[i];
            }
        }
    }

    cout << ans << endl;
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

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

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

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:

10
11
4
11
999999999
2000000000

result:

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