QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673267 | #9528. New Energy Vehicle | ucup-team4474# | WA | 187ms | 77232kb | C++20 | 3.3kb | 2024-10-24 21:27:35 | 2024-10-24 21:27:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long,long long>
#define FF fflush(stdout)
#define inf 0x3f3f3f3f
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
bool Memory_begin;
/*
*/
bool Memory_end;
queue<int> li[100005];
bool in[100005];
signed main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(nullptr);
// cerr << (&Memory_end - &Memory_begin) / 1048576.0 << "MB" << '\n';
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
auto c = a;
vector<pair<int, int>> b(m);
vector<int> lst(n, -1);
for (int i = 0; i < m; i++)
{
cin >> b[i].first >> b[i].second, b[i].second -= 1;
lst[b[i].second] = i;
li[b[i].se].push(i);
}
vector<vector<int>> pos(m + 1);
for (int i = 0; i < n; i++)
pos[lst[i] + 1].push_back(i);
long long ans = 0, remain = 0;
int pre = 0;
priority_queue<int,vector<int>,greater<int> > p;
for(int i=0;i<n;i++)
if(li[i].size())p.push(li[i].front()),li[i].pop();
for (int i = 0; i < m; i++)
{//cout<<i<<endl;
while(p.size()&&p.top()<i)
{
int id=b[p.top()].se;
p.pop();
if(li[id].size())
p.push(li[id].front()),li[id].pop();
else in[id]=0;
}
for (auto &id : pos[i])
remain += a[id], a[id] = 0;
while (pre < b[i].first)
{
if(p.size())
{
int id=b[p.top()].second;
int tmp = b[i].first - pre;
int u = min(tmp, a[id]);
ans += u, a[id] -= u, pre += u;
if(!a[id])p.pop(),in[id]=0;
if (pre == b[i].first)
break;
// if(li[id].size())
// p.push(mp(b[li[id].front()].first,id)),li[id].pop();
}
else if (remain)
{
int tmp = b[i].first - pre;
int u = min(1ll * tmp, remain);
ans += u, remain -= u, pre += u;
if (pre == b[i].first)
break;
}
else
break;
}
if (pre < b[i].first)
break;
a[b[i].second] = c[b[i].second];
int id=b[i].se;
if(!in[id])
{
in[id]=1;
if(li[id].size())
p.push(li[id].front()),li[id].pop();
}
}
ans += remain;
for (int i = 0; i < n; i++)
ans += a[i];
cout << ans << '\n';
for(int i=0;i<max(n,m);i++)
in[i]=0;
for(int i=0;i<max(n,m);i++)
while(li[i].size())li[i].pop();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 70776kb
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: 0
Accepted
time: 11ms
memory: 70800kb
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 11 4 11 999999999 2000000000
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 141ms
memory: 76792kb
input:
10 230 8042 599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...
output:
1543020 1578939 1526016 1527381 1547404 1564631 1051729 1548178 1114634 1072253
result:
ok 10 lines
Test #4:
score: -100
Wrong Answer
time: 187ms
memory: 77232kb
input:
3 100000 100000 1 2 1 1 10 1 17 34 1 1 20 14 4 24 3 1 3 2 7 4 6 3 1 18 1 4 2 1 3 8 3 2 4 1 10 4 23 14 4 16 4 9 8 3 5 2 6 2 2 3 1 7 3 25 10 3 5 3 1 2 14 3 1 3 8 19 3 4 5 7 4 22 2 2 3 3 8 11 8 8 1 9 1 4 2 10 9 8 13 7 21 14 1 27 4 3 2 13 8 1 3 1 5 1 1 1 12 3 4 2 4 10 2 2 10 2 2 14 1 11 1 1 6 1 1 1 2 4 ...
output:
1117677 1116035 1092827
result:
wrong answer 1st lines differ - expected: '1117713', found: '1117677'