QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793307 | #9528. New Energy Vehicle | xixu | WA | 0ms | 3680kb | C++23 | 2.0kb | 2024-11-29 18:28:48 | 2024-11-29 18:28:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#define int long long
// #define int __int128
#define re read()
#define pr(x) print(x)
#define fup(a, b, c, d) for(int a = (b); a <= (c); a += (d))
#define fdo(a, b, c, d) for(int a = (b); a >= (c); a -= (d))
typedef long long ll;
typedef pair<int , int> PII;
typedef map<int , int> MII;
const int inf = 0x3f3f3f3f, N = 2e6 + 10, M = 4e5 + 10, mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m;
int a[N];
bool cmp(int a, int b)
{
return a > b;
}
void solve()
{
set<PII> heap;
cin >> n >> m;
vector<vector<int>> v(n + 10, vector<int>(0));
vector<PII> ve;
vector<int> now(n + 10);
fup(i, 1, n, 1) {
cin >> a[i];
now[i] = a[i];
}
fup(i, 1, m, 1) {
int x, t;
cin >> x >> t;
ve.push_back({x, t});
v[t].push_back(x);
}
fup(i, 1, n, 1) {
v[i].push_back(inf);
sort(v[i].begin(), v[i].end(), cmp);
}
fup(i, 1, n, 1) {
heap.insert({v[i].back(), i});
v[i].pop_back();
}
int lx = 0;
fup(i, 0, m - 1, 1) {
auto e = ve[i];
int x, op, f = 0;
x = e.first, op = e.second;
int su = 0;
while(heap.size()) {
auto t = *(heap.begin());
if(su + now[t.second] > x) {
f = 1;
now[t.second] -= (x - su);
break ;
}
heap.erase(heap.begin());
su += now[t.second];
now[t.second] = 0;
}
if(!f) {
cout << lx + su << '\n';
return ;
}
now[op] = a[op];
heap.erase({x, op});
if(!v[op].size()) {
heap.insert({v[op].back(), op});
v[op].pop_back();
}
lx = x;
}
int ans = lx;
// cout << lx << '\n';
// cout << heap.size() << '\n';
fup(i, 1, n, 1) {
for(auto x : v[i]) {
heap.insert({x, i});
}
}
while(heap.size()) {
auto t = *(heap.begin());
heap.erase(heap.begin());
ans += now[t.second];
}
cout << ans << '\n';
// cout << '\n';
}
signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int _ = 1;
cin >> _;
while(_ --)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
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: 3560kb
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:
6 5 4 5 999999999 1000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'