QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697053 | #9528. New Energy Vehicle | ranxi | TL | 0ms | 3588kb | C++23 | 2.4kb | 2024-11-01 10:00:36 | 2024-11-01 10:00:36 |
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;
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<PII>info(m+1);
for(int i = 1;i<=m;i++)
{
cin >> info[i].first >> info[i].second;
q[info[i].second].push(info[i].first);
}
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({1e9+10,i});
}
}
bool f = true;
ll ans = 0;//现在的位置
for(int i = 1;i<=m;i++){
int dis = info[i].first - ans;
int leng = 0;
while (!q.empty()) {
if (leng + b[pq.top().second] < dis) {
leng += b[pq.top().second];
b[pq.top().second] = 0;
pq.pop();
} else {
b[pq.top().second] -= (dis - leng);
if (b[pq.top().second] == 0)
pq.pop();
leng = dis;
break;
}
}
if (leng < dis) {
f = false;
ans += leng;
break;
}
if(!pq.empty() && pq.top().second==info[i].second)pq.pop();
if(q[info[i].second].size())
{
pq.push({q[info[i].second].front(),info[i].second});
q[info[i].second].pop();
}
else
{
pq.push({1e9+10,info[i].second});
}
b[info[i].second] = a[info[i].second];
ans = info[i].first;
}
if(f){
while(pq.size())
{
ans += b[pq.top().second];
pq.pop();
}
}
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: 100
Accepted
time: 0ms
memory: 3588kb
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
Time Limit Exceeded
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