QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684834#9528. New Energy Vehiclekano07WA 4ms33624kbC++171.9kb2024-10-28 16:08:292024-10-28 16:08:30

Judging History

This is the latest submission verdict.

  • [2024-10-28 16:08:30]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 33624kb
  • [2024-10-28 16:08:29]
  • Submitted

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using db = long double;
mt19937 rnd(time(0));
class JudTime {
public:
    chrono::time_point<chrono::high_resolution_clock> start, end;
    JudTime() : start(chrono::high_resolution_clock::now()) {}
    ~JudTime() {
        end = chrono::high_resolution_clock::now();
        cerr << fixed << setprecision(6) << chrono::duration<double>(end - start).count()
             << " seconds" << endl;
    }
};
const ll N = 1e6 + 5;
ll a[N], b[N];
ll last[N];
ll x[N];
vector<pll> v[N];
void solve() {
    ll n, m;
    cin >> n >> m;
    for (ll i = 0; i <= max(n, m); i++) {
        a[i] = b[i] = last[i] = 0;
        v[i].clear();
    }
    for (ll i = 1; i <= n; i++) {
        cin >> b[i];
        a[i] = b[i];
    }
    multiset<pll> st;
    for (ll i = 1; i <= m; i++) {
        ll y;
        cin >> x[i] >> y;
        v[last[y]].push_back({x[i], a[y]});
        last[y] = i;
    }
    x[m + 1] = 1e18;
    for (int i = 1; i <= n; i++) {
        v[last[i]].push_back({1e18, a[i]});
    }
    ll ans = 0;
    for (ll i = 0; i <= m + 1; i++) {
        auto xx = v[i];
        for (auto i : xx) st.insert(i);
        ll cost = x[i + 1] - x[i];
        vector<pll> tmp;
        while (!st.empty() && cost > 0) {
            auto [l, y] = *st.begin();
            st.erase(st.begin());
            if (l <= x[i]) continue;
            ll org = min(y, cost);
            y -= org;
            cost -= org;
            ans += org;
        }
        if (cost > 0) {
            cout << ans << endl;
            return;
        }
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //   JudTime judTime;
    ll T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 33624kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

11
9

result:

wrong answer 1st lines differ - expected: '12', found: '11'