CF1650C Solution 2022-07-29 作者 Lotuses 893 字 本文最后编辑于 2年 前,其中的内容可能需要更新。 1. Solution Solution 只要取出 个点,都可以说明这些点可以配对(从左到右,从右到左依次配对)。 所以,我们只需要以代价排一遍序,左边取 个数,再以坐标为关键字排序配对即可。 1234567891011121314151617181920212223242526272829#include<bits/stdc++.h>using namespace std;struct Node{ int x,w,id;}nd[200001];vector<Node> ans;bool cmp(Node a,Node b) { return a.w<b.w; }bool cmp2(Node a,Node b) { return a.x<b.x; }int main(){ int t; cin>>t; while(t--) { int n,m,sum=0; cin>>n>>m; for(int i=1;i<=m;i++) nd[i].id=i; for(int i=1;i<=m;i++) cin>>nd[i].x>>nd[i].w; sort(nd+1,nd+m+1,cmp); ans.clear(); for(int i=1;i<=n*2;i++) sum+=nd[i].w,ans.push_back(nd[i]); cout<<sum<<endl; sort(ans.begin(),ans.end(),cmp2); for(int i=0;i<ans.size()/2;i++) cout<<ans[i].id<<" "<<ans[ans.size()-i-1].id<<endl; } return 0;} 复制 本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可 < 上一篇 下一篇 > Please enable JavaScript to view the comments powered by Gitalk.