Advertisement
Sreekar_0125

Untitled

Mar 3rd, 2024
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>    
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. template <class T>
  7. using pbds =
  8.     tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  9. // #define cerr if(false)cerr
  10. #define int long long
  11. #define pb push_back
  12. #define F first
  13. #define S second
  14. #define yes cout << "Yes\n"
  15. #define no cout << "No\n"
  16. #define yn(x) x ? yes : no
  17. #define f(i, s, e) for (int i = s; i < e; i++)
  18. #define vi vector<int>
  19. #define vb vector<bool>
  20. #define pii pair<int, int>
  21. #define vpi vector<pii>
  22. #define umi unordered_map<int, int>
  23. #define mi map<int, int>
  24. #define si set<int>
  25. #define sc set<char>
  26. #define maxheap priority_queue<int>
  27. #define minheap priority_queue<int, vector<int>, greater<int>>
  28. #define all(x) x.begin(), x.end()
  29. #define minele(x) *min_element(all(x))
  30. #define maxele(x) *max_element(all(x))
  31. #define endl '\n'
  32.  
  33. const int N = 2e5;
  34. const int MOD = 1e9 + 7;
  35.  
  36.  
  37. #ifndef ONLINE_JUDGE
  38. #define debug(x)            \
  39.     cerr << (#x) << " is "; \
  40.     _print(x)
  41. #define dbg(x)              \
  42.     cerr << (#x) << " is " << x << endl;
  43. #else
  44. #define debug(x)
  45. #define dbg(x)
  46. #endif
  47.  
  48.  
  49. template <typename T>
  50. void _print(T a)
  51. {
  52.     cerr << a;
  53. }
  54. template <typename T>
  55. void print(T a)
  56. {
  57.     cout << a << ' ';
  58. }
  59. template <typename T>
  60. void println(T a)
  61. {
  62.     cout << a << endl;
  63. }
  64. template <class T>
  65. istream &operator>>(istream &is, vector<T> &a)
  66. {
  67.     for (auto &x : a)
  68.         is >> x;
  69.     return is;
  70. }
  71. template <class T>
  72. ostream &operator<<(ostream &os, const vector<T> &a)
  73. {
  74.     for (const auto &x : a)
  75.         os << x << ' ';
  76.     return os;
  77. }
  78.  
  79. template <class T, class V>
  80. void _print(pair<T, V> p);
  81. template <class T>
  82. void _print(vector<T> v);
  83. template <class T>
  84. void _print(set<T> v);
  85. template <class T, class V>
  86. void _print(map<T, V> v);
  87. template <class T>
  88. void _print(multiset<T> v);
  89. template <class T, class V>
  90. void _print(pair<T, V> p)
  91. {
  92.     cerr << "{";
  93.     _print(p.F);
  94.     cerr << ",";
  95.     _print(p.S);
  96.     cerr << "} ";
  97. }
  98. template <class T>
  99. void _print(vector<T> v)
  100. {
  101.     cerr << "[ ";
  102.     for (T i : v)
  103.     {
  104.         _print(i);
  105.         cerr << " ";
  106.     }
  107.     cerr << "]";
  108.     cerr << endl;
  109. }
  110. template <class T>
  111. void _print(set<T> v)
  112. {
  113.     cerr << "[ ";
  114.     for (T i : v)
  115.     {
  116.         _print(i);
  117.         cerr << " ";
  118.     }
  119.     cerr << "]";
  120.     cerr << endl;
  121. }
  122. template <class T>
  123. void _print(multiset<T> v)
  124. {
  125.     cerr << "[ ";
  126.     for (T i : v)
  127.     {
  128.         _print(i);
  129.         cerr << " ";
  130.     }
  131.     cerr << "]";
  132.     cerr << endl;
  133. }
  134. template <class T, class V>
  135. void _print(map<T, V> v)
  136. {
  137.     cerr << "[ ";
  138.     for (auto i : v)
  139.     {
  140.         _print(i);
  141.         cerr << " ";
  142.     }
  143.     cerr << "]";
  144.     cerr << endl;
  145. }
  146. template <class T, class V>
  147. void _print(unordered_map<T, V> v)
  148. {
  149.     cerr << "[ ";
  150.     for (auto i : v)
  151.     {
  152.         _print(i);
  153.         cerr << " ";
  154.     }
  155.     cerr << "]";
  156.     cerr << endl;
  157. }
  158.  
  159. /////////////Sieve///////////////
  160. // vb sieve(N + 5, true);
  161. // vi primes;
  162. // void gensieve()
  163. // {
  164. //     sieve[0] = sieve[1] = false;
  165. //     for (int i = 2; i <= sqrt(N); i++)
  166. //     {
  167. //         if (sieve[i])
  168. //         {
  169. //             for (int j = i * i; j <= N; j += i)
  170. //                 sieve[j] = false;
  171. //         }
  172. //     }
  173. //     for (int i = 2; i <= N; i++)
  174. //     {
  175. //         if (sieve[i])
  176. //             primes.pb(i);
  177. //     }
  178. // }
  179. ////////////////////////////////
  180.  
  181. int binpow(int a, int b)
  182. {
  183.     int ans = 1;
  184.     a %= MOD;
  185.     while(b)
  186.     {
  187.         if(b & 1)
  188.             ans = ((ans % MOD) * (a % MOD)) % MOD;
  189.        
  190.         a = ((a % MOD) * (a % MOD)) % MOD;
  191.         b >>= 1;
  192.     }
  193.     return ans;
  194. }
  195.  
  196. void fast()
  197. {
  198.     ios_base::sync_with_stdio(false);
  199.     cin.tie(NULL);
  200.     cout.tie(NULL);
  201. }
  202.  
  203. void init_code()
  204. {
  205. #ifndef ONLINE_JUDGE
  206.     freopen("input.txt", "r", stdin);
  207.     freopen("output.txt", "w", stdout);
  208.     freopen("error.txt", "w", stderr);
  209. #endif // ONLINE_JUDGE
  210. }
  211.  
  212. bool cmp(pii &p1, pii &p2)
  213. {
  214.     if(p1.F == p2.F)
  215.     {
  216.         return p1.S > p2.S;
  217.     }
  218.     return p1.F > p2.F;
  219. }
  220.  
  221. void solve()
  222. {
  223.     int n, k;
  224.     cin >> n >> k;
  225.  
  226.     vpi points;
  227.     f(i, 0, n)
  228.     {
  229.         int a, b;
  230.         cin >> a >> b;
  231.         points.pb({b, a});
  232.     }
  233.     sort(all(points), cmp);
  234.     int ans = 0;
  235.     int i = 0;
  236.     debug(points);
  237.     while(k > 0)
  238.     {
  239.         if(points[i].S <= k)
  240.         {
  241.             ans += points[i].F * points[i].S;
  242.             k -= points[i].S;
  243.             i++;
  244.         }
  245.         else
  246.         {
  247.             ans += k * points[i].F;
  248.             break;
  249.         }
  250.     }
  251.  
  252.     println(ans);
  253. }
  254.  
  255. signed main()
  256. {
  257.     // init_code();
  258.     fast();
  259.     int t = 1;
  260.     // cin >> t;
  261.     while (t--)
  262.     {
  263.         solve();
  264.     }
  265.     return 0;
  266. }
  267.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement