标签:iter NPU const insert opera inpu namespace cstring bsp
比较好的一道贪心题.
code:
#include <set> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #define N 100009 #define ll long long #define setIO(s) freopen(s".in","r",stdin) using namespace std; struct data { int opt,x,y; }a[N]; struct node { double x; int id; node(double x=0,int id=0):x(x),id(id){} bool operator<(const node b) const { return x==b.x?id<b.id:x>b.x; } }; int arr[N],ma[N]; bool cm(int i,int j) { return a[i].opt<a[j].opt; } vector<int>add[N]; vector<int>ans; set<node>se; set<node>::iterator it; bool cmp(int i,int j) { return a[i].y>a[j].y; } int main() { // setIO("input"); int k,n,m; scanf("%d%d%d",&k,&n,&m); for(int i=1;i<=k;++i) scanf("%d",&arr[i]); for(int i=1;i<=n;++i) { scanf("%d%d%d",&a[i].opt,&a[i].x,&a[i].y); if(a[i].opt==1&&a[ma[a[i].x]].y<a[i].y) { ma[a[i].x]=i; } } for(int i=1;i<=n;++i) { if(a[i].opt==1) { if(i==ma[a[i].x]&&a[i].y>arr[a[i].x]) { a[i].y-=arr[a[i].x]; add[a[i].x].push_back(i); } } if(a[i].opt==2) { add[a[i].x].push_back(i); } if(a[i].opt==3) { se.insert(node(1.00*a[i].y,i)); } } for(int i=1;i<=k;++i) { sort(add[i].begin(),add[i].end(),cmp); ll p=arr[i]; for(int j=0;j<add[i].size();++j) { se.insert(node((double)(p+a[add[i][j]].y)/p,add[i][j])); p+=a[add[i][j]].y; } } printf("%d\n",min((int)se.size(),m)); int cnt=1; for(it=se.begin();it!=se.end()&&cnt<=m;it++) { ans.push_back((*it).id); ++cnt; } sort(ans.begin(),ans.end(),cm); for(int i=0;i<ans.size();++i) printf("%d ",ans[i]); return 0; }
标签:iter NPU const insert opera inpu namespace cstring bsp
原文地址:https://www.cnblogs.com/guangheli/p/13283081.html