QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702489 | #9528. New Energy Vehicle | Cocoder | WA | 2ms | 11372kb | C++14 | 1.6kb | 2024-11-02 16:05:06 | 2024-11-02 16:05:07 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define inf (int)1e9+10
using namespace std;
const int N=2e5+10;
struct Battery
{
int id,w,x;
bool operator < (const Battery &b) const
{
return x>b.x;
}//按位置从近到远排
};
priority_queue <Battery> q;
int p[N];
pair <int,int> sta[N];
int a[N];
vector <int> pos[N];
int n,m;
void init()
{
for(int i=1;i<=n;i++) pos[i].clear(),p[i]=0;
}
void solve()
{
cin>>n>>m;
init();
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++)
{
int x,t;
cin>>x>>t;
sta[i]=make_pair(x,t);
pos[t].push_back(x);
}
for(int i=1;i<=n;i++) pos[i].push_back(inf);
for(int i=1;i<=n;i++)
q.push(Battery{i,a[i],pos[i][p[i]++]});
for(int i=1;i<=m;i++)
{
ll dis=sta[i].first-sta[i-1].first,sum=0;
while(!q.empty())
{
if(sum==dis) break;
Battery u=q.top();
q.pop();
if(dis-sum>=u.w) sum+=u.w;
else
{
u.w-=dis-sum;
q.push(u);
sum=dis;
}
}
int t=sta[i].second;
if(!q.empty()&&q.top().id==t) q.pop();
if(p[t]==(int)pos[t].size()) continue;
q.push(Battery{t,a[t],pos[t][p[t]++]});
}
ll ans=sta[m].first;
while(!q.empty())
{
int u=q.top().w;
ans+=u;
q.pop();
}
cout<<ans<<endl;
return ;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11372kb
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: 10260kb
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 11 11 1999999999 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '11'