Advertisement
Falak_Ahmed_Shakib

muti map;

Nov 6th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 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++)cin>>ara[i];
  26. }
  27.  
  28. #define eb emplace_back
  29. int main() {
  30.  
  31.  
  32. multimap<ll,ll>m;
  33.  
  34. ll n,m1,a,b;
  35. cin>>n>>m1;
  36. for(ll i=0; i<m1;i++)
  37. {
  38. cin>>b>>a;
  39. //m[a]=b;
  40.  
  41. m.insert({a,b});
  42.  
  43. }
  44. vector<pair<ll,ll>>v;
  45. // cout<<endl;
  46. for(auto x:m)
  47. {
  48. a=x.fi;
  49. b=x.se;
  50. // cout<<a<<" "<<b<<endl;
  51. v.pb({a,b});
  52.  
  53. }
  54.  
  55. ll cnt=0,ans=0;
  56. // cout<<endl;
  57. for(ll i=m1-1; ;i--)
  58. { // cout<<v[i].fi<<" "<<v[i].se<<endl;
  59. if(v[i].se<n)
  60. {
  61.  
  62. ans=ans+(v[i].fi*v[i].se);
  63. n=n-v[i].se;
  64. if(i==0)break;
  65. }
  66. else
  67. {
  68. ans=ans+(n*v[i].fi);
  69. break ;
  70. }
  71.  
  72. }
  73.  
  74. cout<<ans<<endl;
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement