FEgor04

Untitled

Sep 10th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define DEBUG
  3. using namespace std;
  4. int main() {
  5.     ios_base::sync_with_stdio(0);
  6.     cin.tie(NULL);
  7.     long long k, n, a, b;
  8.     cin >> k >> n;
  9.     cout << 42 << "\n";
  10.     vector<pair <long long, long long>> mp(n, {0, 0});
  11.     long long count = 0;
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> mp[i].first >> mp[i].second;
  14.     }
  15.     sort(mp.begin(), mp.end());
  16.     for(int i = 0; i < mp.size(); i++) {
  17.         if(mp[i].first * mp[i].second <= k) {
  18.             count += mp[i].second;
  19.             k -= mp[i].second * mp[i].first;
  20.         }
  21.         else {
  22.             int a = 0;
  23.             for(int j = mp[i].second; j * mp[i].first > k; i--) {
  24.                 a = i;
  25.             }
  26.             a--;
  27.             count += a;
  28.             k -= mp[i].first * a;
  29.         }
  30.     }
  31.     cout << count;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment