QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744820#9730. Elevator IIyylxWA 1ms3548kbC++141.5kb2024-11-13 23:38:492024-11-13 23:38:49

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 23:38:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3548kb
  • [2024-11-13 23:38:49]
  • 提交

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)