Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include<cstdio>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. struct mem
  6. {
  7. int x,y;
  8. };
  9. mem v[10005];
  10. bool cmp(mem a, mem b)
  11. {
  12. if(a.x==b.x) return a.y<b.y;
  13. return a.x>b.x;
  14. }
  15. int timp[10005];
  16. bool pus[10005];
  17. vector<mem>ans;
  18. int main()
  19. {
  20. freopen("credite.in","r",stdin);
  21. freopen("credite.out","w",stdout);
  22. int s=0,n,y1,x1,cnt=0;
  23. scanf("%d",&n);
  24. for(register int i=1;i<=n;i++)
  25. {
  26. scanf("%d%d",&x1,&y1);
  27. v[i].x=x1;
  28. v[i].y=y1;
  29. }
  30. sort(v+1,v+n+1,cmp);
  31. mem temp;
  32. for(register int i=1;i<=n;i++)
  33. {
  34. if(timp[v[i].y]<v[i].y)
  35. {
  36.  
  37. timp[v[i].y]++;
  38. temp.x=v[i].x;
  39. temp.y=v[i].y;
  40. ans.push_back(temp);
  41. //if(ans.size()==cnt) break;
  42. }
  43. }
  44. for(register int i=0;i<ans.size();i++)
  45. {
  46. int cnt=ans[i].y;
  47. while(pus[cnt])
  48. cnt--;
  49. if(cnt>=1)
  50. {
  51. pus[cnt]=1;
  52. //printf("%d\n",ans[i].x);
  53. s+=ans[i].x;
  54. }
  55. }
  56. printf("%d",s);
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement