Advertisement
Falak_Ahmed_Shakib

vector + pair+ reverse sort

Nov 6th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /*
  2. , \ / ,
  3. / \ )\__/( / \
  4. / \ (_\ /_) / \
  5. ____/_____\__\@ @/___/_____\____
  6. | |\../| |
  7. | \VV/ |
  8. | ------___------- |
  9. |__________Chuta Dragon___________|
  10. | /\ / \\ \ /\ |
  11. | / V )) V \ |
  12. |/ ` // ' \|
  13. ` V '
  14. */
  15. #include<bits/stdc++.h>
  16. using namespace std;
  17. typedef long long ll;
  18. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  19. #define fi first
  20. //#define se second
  21. #define pb push_back
  22. #define eb emplace_back
  23. void input(ll ara[],ll n)
  24. {
  25. for(ll i=0; i<n; i++)
  26. {cin>>ara[i];
  27. // if(ara[i]>mx)mx=ara[i];
  28. // if(ara[i]<mn)mn=ara[i];
  29. // m[ara[i]]++;
  30.  
  31. }
  32. }
  33.  
  34. #define eb emplace_back
  35. int main()
  36. {
  37. ll n,m,a,b,i;
  38. cin>>n>>m;
  39. vector<pair<ll,ll>>v;
  40.  
  41. while(m--)
  42. {
  43. cin>>a>>b;
  44. v.pb({b,a});
  45. }
  46.  
  47. sort(v.rbegin(),v.rend());
  48.  
  49. int x=0,ans=0;
  50.  
  51. for(i=0;i<v.size();i++)
  52. {
  53. if((x+v[i].second)<=n)
  54. {
  55. ans+=(v[i].first*v[i].second);
  56. x+=v[i].second;
  57. }
  58. else
  59. {
  60. int p=n-x;
  61. ans+=(p*v[i].first);
  62. break;
  63. }
  64. }
  65.  
  66. cout<<ans<<endl;
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement