QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744820 | #9730. Elevator II | yylx | WA | 1ms | 3548kb | C++14 | 1.5kb | 2024-11-13 23:38:49 | 2024-11-13 23:38:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int t,n,f,cur;
long long op,ext;
priority_queue<pair<int,int> > q;
vector<int> s;
struct ele
{
int ind,l,r;
};
ele es[100001];
bool cmp(ele a,ele b)
{
if(a.l!=b.l) return a.l<b.l;
else return a.r>b.r;
}
void solve()
{
op=0;
ext=0;
s.clear();
cin>>n>>f;
for(int i=1;i<=n;i+=1)
{
cin>>es[i].l>>es[i].r;
op+=es[i].r-es[i].l;
es[i].ind=i;
}
sort(es+1,es+n+1,cmp);
cur=1;
while(s.size()<n)
{
while(cur<=n && es[cur].l<=f)
{
q.push(make_pair(es[cur].r,es[cur].ind));
cur+=1;
}
if(q.size()==0)
{
ext+=es[cur].l-f;
f=es[cur].r;
s.push_back(es[cur].ind);
cur+=1;
continue;
}
if(q.top().first<f)
{
if(cur==n+1)
{
s.push_back(q.top().second);
q.pop();
}
else
{
ext+=es[cur].l-f;
f=es[cur].r;
s.push_back(es[cur].ind);
cur+=1;
}
continue;
}
s.push_back(q.top().second);
q.pop();
f=q.top().first;
}
cout<<op+ext<<endl;
for(int i=0;i<n;i+=1) cout<<s[i]<<" ";
cout<<endl;
}
int main()
{
cin>>t;
while(t--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3548kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
13 3 1 2 4 5 2 1
result:
wrong answer Participant's cost is 13, which is worse than jury's cost 11 (test case 1)