QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696980 | #9528. New Energy Vehicle | ranxi | RE | 0ms | 0kb | C++23 | 2.3kb | 2024-11-01 09:18:48 | 2024-11-01 09:18:49 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define alls(x) x.begin(),x.end()
#define ull unsigned long long
#define lowbit(x) x&-x
#define lc p<<1
#define rc p<<1|1
#define PII pair<int,int>
#define vi vector<int>
// #define int long long
using namespace std;
const ll inf = 2e18;
const int mod = 998244353;
const int N = 2e5+10;
struct node{
int x;
int id;
};
void solve()
{
int n,m;
cin >> n >> m;
vi a(n+1),b(n+1);
for(int i = 1;i<=n;i++)
{
cin >> a[i];
b[i] = a[i];
}
vector<queue<int>>q(n+1);
vector<node>info(m+1);
for(int i = 1;i<=m;i++)
{
cin >> info[i].x >> info[i].id;
q[info[i].id].push(info[i].x);
}
priority_queue<PII,vector<PII>,greater<PII>>pq;//充电站位置,编号
for(int i = 1;i<=n;i++)
{
if(q[i].size())
{
pq.push({q[i].front(),i});
q[i].pop();
}
else
{
pq.push({2e9,i});
}
}
bool f = true;
ll ans = 0;//现在的位置
for(int i = 1;i<=m;i++){
int dis = info[i].x - ans;
while (!pq.empty())
{
if(b[pq.top().second]>dis)
{
dis = 0;
b[pq.top().second]-=dis;
}
else
{
dis -= b[pq.top().second];
b[pq.top().second] = 0;
pq.pop();
break;
}
}
if(dis)
{
f = false;
ans += info[i].x - ans - dis;
break;
}
if(!pq.empty() && pq.top().second==info[i].id)pq.pop();
if(q[info[i].id].size())
{
pq.push({q[info[i].id].front(),info[i].id});
q[info[i].id].pop();
}
else
{
pq.push({2e9,info[i].id});
}
b[info[i].id] = a[info[i].id];
ans = info[i].x;
}
if(f){
while(pq.size())
{
ans += b[pq.top().second];
}
}
cout<<ans<<'\n';
}
signed main()
{
cout<<fixed<<setprecision(6);
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
// cin >> _;
while(_--)solve();
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1