续 Codeforces 605 B

来源:互联网 发布:淘宝网店客服怎么做 编辑:程序博客网 时间:2024/05/01 15:41

不得不说此题的这种解法比我的逼格高10000倍啊,巧妙地利用过了取反来,用vector排序,而且还迭代器,还auto,而且make_pair的时候也是直接上{},不行不行,思维一定要变通,姿势一定要优美

#include<bits/stdc++.h>using namespace std;const int MAX=1e5+9;int n,m,p1=1,p2=2,p3=1;pair<int,int> ans[MAX];vector<pair<pair<int,int>,int> > edge;int main(){    cin>>n>>m;    for (int i=0,w,t;i<m;i++) cin>>w>>t,edge.push_back({{w,-t},i});    sort(edge.begin(),edge.end());    for (auto e:edge)    {        if (e.first.second==-1) ans[e.second]={0,p1},p1++;        else        {            if (p3==0) p2++,p3=p2-1;            if (p2>=p1 || p3==0) return cout<<-1,0;            ans[e.second]={p2,p3},p3--;        }    }    for (int i=0;i<m;i++) cout<<ans[i].first+1<<" "<<ans[i].second+1<<'\n';}
0 0
原创粉丝点击