QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684735#9528. New Energy VehicleHojstyer#WA 0ms3620kbC++202.1kb2024-10-28 15:29:362024-10-28 15:29:36

Judging History

This is the latest submission verdict.

  • [2024-10-28 15:29:36]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3620kb
  • [2024-10-28 15:29:36]
  • Submitted

answer

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

typedef long long ll;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> vis(n + 1);
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vector<pair<int, int>> f(m + 1);
    vector<queue<int>> pos(n + 1);
    for (int i = 1; i <= m; ++i)
    {
        int x, t;
        cin >> x >> t;
        pos[t].push(i);
        f[i] = {x, t};
    }

    set<array<int, 2>> s;
    for (int i = 1; i <= m; i++)
    {
        auto [x, t] = f[i];
        if (!vis[t])
        {
            vis[t] = 1;
            s.insert({i, a[t]});
        }
    }

    ll sheng = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
            sheng += a[i];
    }

    ll start = 0; // 车停留的位置
    int del = 0;
    array<int, 2> modify;
    for (int i = 1; i <= m; i++)
    {
        auto [x, t] = f[i];
        int need = x - start;
        del = 0;
        modify[0] = 0;
        // 检查是否能到i
        int res = 0;
        for (auto [id, c] : s)
        {
            del++;
            if (res + c > need)
            {
                modify = {i, c - (need - res)};
                res = need;
                break;
            }
            res += c;
        }
        if (res < need)
        {
            int mi = min(need - res, sheng);
            res += mi;
            sheng -= mi;
        }
        start += res;

        // 不能到
        if (res < need)
            break;

        // 能到
        //  处理充电装
        while (del--)
            s.erase(s.begin());
        if (modify[0])
            s.insert(modify);

        // 后面的一个复活
        pos[t].pop();
        if (pos[t].size())
            s.insert({pos[t].front(), a[t]});
        else
            sheng += a[t];
    }

    // 补刀
    start += sheng;

    cout << start << "\n";
}

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

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

    return 0;
}

详细

Test #1:

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

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

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'