QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#759031 | #9528. New Energy Vehicle | W_Trace2# | WA | 0ms | 6656kb | C++14 | 2.8kb | 2024-11-17 21:16:25 | 2024-11-17 21:16:26 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
ll a=0,b=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
return a*b;
}
struct Charge
{
ll next_sta,rest,Kind,Rank;
friend bool operator< (Charge a,Charge b)
{
return a.next_sta>b.next_sta;
}
};
ll n,m,a[100001];
priority_queue<Charge> use,charge;
vector<ll> position[100001];
int two_point(int x,int place)//第一个大于的位置
{
int l=0,r=position[x].size()-1;
while(l<r)
{
int mid=l+r>>1;
if(position[x][mid]<=place)
l=mid+1;
else
r=mid;
}
return l;
}
int main()
{
ll T=read();
while(T--)
{
n=read(),m=read();
for(ll i=1;i<=n;i++)
{
a[i]=read();
position[i].clear();
}
for(ll i=1;i<=m;i++)
{
ll x=read(),y=read();
position[y].push_back(x);
}
for(ll i=1;i<=n;i++)
{
sort(position[i].begin(),position[i].end());
position[i].push_back((1LL<<60));
}
for(ll i=1;i<=n;i++)
{
Charge x;
x.Kind=i;
x.next_sta=position[i][0];
x.Rank=0;
x.rest=a[i];
use.push(x);
}
int nowp=0;
// cout<<"?\n";
Charge tmp;
tmp.next_sta=(1LL<<60);
charge.push(tmp);
while(use.size()!=0)
{
if(use.top().rest+nowp<=min(use.top().next_sta,(charge.top().next_sta)))
{
nowp+=use.top().rest;
Charge x=use.top();
use.pop();
x.rest=0;
charge.push(x);
}
else
{
Charge x=use.top();
Charge y=charge.top();
if(x.next_sta<=y.next_sta)
{
use.pop();
nowp=x.next_sta;
x.rest=a[x.Kind];
x.next_sta=position[x.Kind][two_point(x.Kind,nowp)];
use.push(x);
}
else
{
use.pop();
x.rest-=(y.next_sta-nowp);
nowp+=(y.next_sta-nowp);
use.push(x);
charge.pop();
y.next_sta=position[y.Kind][two_point(y.Kind,nowp)];
y.rest=a[y.Kind];
use.push(y);
}
}
}
cout<<nowp<<'\n';
}
return 0;
}
/*
1
3 1
3 3 3
8 1
1
2 2
5 2
1 2
2 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6656kb
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: 6644kb
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 14 4 17 999999999 1000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'