QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700137 | #9528. New Energy Vehicle | RWeakest | RE | 4ms | 73168kb | C++17 | 1.7kb | 2024-11-02 12:06:16 | 2024-11-02 12:06:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 100;
ll T, n, m, a[N], res[N], x[N], t[N];
deque<ll> lev[N];
struct node {
ll level, number;
node(ll a, ll b) {
level = a, number = b;
}
};
struct cmp {
bool operator()(node a1, node a2) {
return a1.level > a2.level;
}
};
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) res[i] = a[i], lev[i].clear();
for (int i = 1; i <= m; i++) cin >> x[i] >> t[i];
for (int i = 1; i <= m; i++) lev[t[i]].push_back(i);
for (int i = 1; i <= n; i++) lev[i].push_back(m + 1);
priority_queue<node, vector<node>, cmp> q;
for (int i = 1; i <= n; i++) q.emplace(lev[i].front(), i);
ll sum = 0;
for (int i = 1; i <= m; i++) {
while (sum < x[i] && !q.empty()) {
ll p = q.top().number;
q.pop();
ll next = min(res[p], x[i] - sum);
res[p] -= next;
sum += next;
if (res[p] > 0) q.emplace(lev[p].front(), p);
else lev[p].pop_front();
}
res[t[i]] = a[t[i]];
if (q.top().level == i) q.pop();
if (lev[t[i]].front() == i) lev[t[i]].pop_front();
q.emplace(lev[t[i]].front(), t[i]);
}
// printf("res:");
// for (int i = 1; i <= n; i++) printf("%lld ", res[i]);
// printf("\n");
for (int i = 1; i <= n; i++) sum += res[i];
cout << sum << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 73168kb
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
Runtime Error
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