QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706857 | #9528. New Energy Vehicle | leafmaple# | WA | 1ms | 3780kb | C++20 | 1.5kb | 2024-11-03 13:43:14 | 2024-11-03 13:43:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> nxa[100000+10];
int nx[100000+10];
void solve()
{
int n,m;
cin>>n>>m;
vector<int> a(n+1);
for(int i=1;i<=n;i++)
cin>>a[i];
vector<pair<int,int> > now(m+1);
for(int i=1;i<=n;i++)
{
nxa[i].clear();
nx[i] = 0;
}
for(int i=1;i<=m;i++)
{ cin>>now[i].first>>now[i].second ;
nxa[now[i].second].push_back(i);
}
for(int i=1;i<=n;i++)
{
nxa[i].push_back(m+1);
}
priority_queue<pair<int,int> ,vector<pair<int,int> > ,greater<pair<int,int> > > q;
for(int i=1;i<=n;i++)
{
q.push({nxa[i][0],a[i]});
}
int nowl = 0 ;
for(int i=1;i<=m;i++)
{
while(!q.empty()&&now[i].first != nowl )
{
auto[u,w] = q.top();
q.pop();
int sub = now[i].first - nowl;
if(sub < w)
{
nowl = now[i].first;
w -= sub;
if(now[i].second == u)
{
nx[ now[i].second ] ++;
q.push({nxa[now[i].second][nx[now[i].second]],a[now[i].second]});
}
else
{
q.push({u,w});
nx[ now[i].second ] ++;
q.push({nxa[now[i].second][nx[now[i].second]],a[now[i].second]});
}
}
else
{
nowl = nowl + w ;
}
}
if(now[i].first != nowl)
{
break;
}
}
while(!q.empty())
{
auto [u,w] = q.top();
q.pop();
nowl += w;
}
cout<<nowl<<endl;
}
signed main (){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
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: 1ms
memory: 3544kb
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 11 4 11 999999999 1000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'