Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<vector>
- #include<algorithm>
- using namespace std;
- struct mem
- {
- int x,y;
- };
- mem v[10005];
- bool cmp(mem a, mem b)
- {
- if(a.x==b.x) return a.y<b.y;
- return a.x>b.x;
- }
- int timp[10005];
- bool pus[10005];
- vector<mem>ans;
- int main()
- {
- freopen("credite.in","r",stdin);
- freopen("credite.out","w",stdout);
- int s=0,n,y1,x1,cnt=0;
- scanf("%d",&n);
- for(register int i=1;i<=n;i++)
- {
- scanf("%d%d",&x1,&y1);
- v[i].x=x1;
- v[i].y=y1;
- }
- sort(v+1,v+n+1,cmp);
- mem temp;
- for(register int i=1;i<=n;i++)
- {
- if(timp[v[i].y]<v[i].y)
- {
- timp[v[i].y]++;
- temp.x=v[i].x;
- temp.y=v[i].y;
- ans.push_back(temp);
- //if(ans.size()==cnt) break;
- }
- }
- for(register int i=0;i<ans.size();i++)
- {
- int cnt=ans[i].y;
- while(pus[cnt])
- cnt--;
- if(cnt>=1)
- {
- pus[cnt]=1;
- //printf("%d\n",ans[i].x);
- s+=ans[i].x;
- }
- }
- printf("%d",s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement