QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746410#9528. New Energy VehicleWhxxxxx318WA 0ms3788kbC++173.3kb2024-11-14 14:31:272024-11-14 14:31:28

Judging History

This is the latest submission verdict.

  • [2024-11-14 14:31:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3788kb
  • [2024-11-14 14:31:27]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int a[N];
int used[N];
int vis[N];
struct node
{
    int pos, x;
    bool operator<(node t)
    {
        return pos < t.pos;
    }
};
void solve()
{
    int n, m;
    cin >> n >> m;
    int tot = 0, used_tot = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        used[i] = 0;
    }
    vector<node> v;
    set<int> st1, st2;
    for (int i = 1; i <= m; i++)
    {
        int x, t;
        cin >> x >> t;
        v.push_back({x, t});
        st1.insert(t);
        vis[t] = 1;
    }
    sort(v.begin(), v.end());
    for (int i = 1; i <= n; i++)
        if (!vis[i])
            tot += a[i];
    int now = 0;
    for (int i = 0; i < m; i++)
    {
        auto [pos, x] = v[i];
        if (a[x] - used[x] >= used_tot)
        {
            used[x] += used_tot;
            used_tot = 0;
        }
        else
        {
            used_tot -= a[x] - used[x];
            used[x] = a[x];
            if (st1.count(x))
            {
                st1.erase(x);
                st2.insert(x);
            }
        }
        while (!st2.empty() && a[x] - used[x])
        {
            int t = *st2.begin();
            if (a[x] - used[x] >= a[t])
            {
                used[x] += a[t];
                used[t] = 0;
                st1.insert(t);
                st2.erase(t);
            }
            else
            {
                used[t] -= a[x] - used[x];
                used[x] = a[x];
                st1.insert(t);
                st2.erase(t);
                st1.erase(x);
                st2.insert(x);
                break;
            }
        }
        if (a[x] - used[x] >= pos - now)
        {
            now = pos;
            used[x] = 0;
            continue;
        }
        else if (st1.count(x))
        {
            now += a[x] - used[x];
            used[x] = a[x];
            st1.erase(x);
            st2.insert(x);
        }
        if (tot - used_tot > 0)
        {
            if (tot - used_tot >= pos - now)
            {
                used_tot += pos - now;
                now = pos;
            }
            else
            {
                now += tot - used_tot;
                used_tot = tot;
            }
        }
        while (!st1.empty())
        {
            int t = *st1.begin();
            if (a[t] - used[t] >= pos - now)
            {
                now = pos;
                used[t] += pos - now;
                break;
            }
            else
            {
                now += a[t] - used[t];
                used[t] = a[t];
                st1.erase(t);
                st2.insert(t);
            }
        }
        if (now != pos)
        {
            cout << now << endl;
            return;
        }
        used[x] = 0;
        if (st2.count(x))
        {
            st2.erase(x);
            st1.insert(x);
        }
    }
    for (auto u : st1)
    {
        now += a[u] - used[u];
    }
    now += tot - used_tot;
    cout << now << endl;
}
signed main()
{
    // freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    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: 3528kb

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

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

result:

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