QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686076 | #9528. New Energy Vehicle | xmseer | WA | 1ms | 4584kb | C++17 | 2.2kb | 2024-10-28 23:51:15 | 2024-10-28 23:51:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int N = 1e5 + 7;
int a[N];
struct Station{
int x = 0, t;
bool operator<(const Station &other){
return x < other.x;
}
}s[N];
void solve()
{
int n, m;
cin>>n>>m;
vector<vector<int> > bind(n+1);
vector<int> use(n+1);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>s[i].x>>s[i].t;
}
sort(s+1, s+m+1);
for(int i=1;i<=m;i++)
{
bind[s[i].t].push_back(i);
}
ll fre = 0;
priority_queue<pii, vector<pii>, greater<pii> > pq;
for(int i=1;i<=n;i++)
{
if(bind[i].size()==0) {
fre += a[i];
}else {
pq.push({bind[i][0], a[i]});
use[i]++;
}
}
ll bet = 0;
for(int i=1;i<=m;i++)
{
int dis = s[i].x - s[i-1].x;
while(pq.size() && dis)
{
auto [sid, c] = pq.top();
pq.pop();
if(dis>=c) {
dis -= c;
}else {
dis = 0;
c -= dis;
pq.push({sid, c});
}
}
if(dis) {
if(dis > fre) {
cout<<s[i].x - (dis-fre);
return;
}else{
fre -= dis;
}
}
if(pq.size()) {
auto [sid, c] = pq.top();
if(sid==i) {
pq.pop();
}
int bid = s[i].t;
if(use[bid] < bind[bid].size()) {
pq.push({bind[bid][use[bid]], a[bid]});
use[bid]++;
} else {
fre += a[bid];
}
}
else {
int bid = s[i].t;
if(use[bid] < bind[bid].size()) {
pq.push({bind[bid][use[bid]], a[bid]});
use[bid]++;
} else {
fre += a[bid];
}
}
}
cout<<s[m].x + fre<<endl;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T = 1;
cin>>T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4584kb
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: 4384kb
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 411 9999999992000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '411'