Advertisement
Korotkodul

ege_26_do

Feb 14th, 2023 (edited)
721
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 1 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. #include <fstream>
  51.  
  52. pii f(vector <pii> a, int S) {
  53.     sort(a.begin(), a.end());
  54.     int n = a.size();
  55.     int res = 0;
  56.     for (int i = 0; i < n; ++i) {
  57.         while (S - a[i].first >= 0 && a[i].second - 1 >= 0) {
  58.             S -= a[i].first;
  59.             a[i].second--;
  60.             res++;
  61.         }
  62.     }
  63.     return {res, S};
  64. }
  65.  
  66. int main() {
  67.     string data;
  68.     ifstream file("26.txt");
  69.     vector <pii> a, b;
  70.     vector <pii> A, B;
  71.     getline(file, data);
  72.     int S, N;
  73.     string SN, SS;
  74.     int i = 0;
  75.  
  76.     while (data[i] == ' ' ) {
  77.         i++;
  78.  
  79.     }
  80.     //cout << "a\n";
  81.     while (data[i] != ' ') {
  82.         SN += data[i];
  83.         i++;
  84.     }
  85.     //cout << "b\n";
  86.     while (data[i] == ' ') {
  87.         i++;
  88.     }
  89.     //cout << "c\n";
  90.     //cout << "data = " << data << "\n";
  91.     while (i < data.size() && data[i] != ' ' ) {
  92.         SS += data[i];
  93.         i++;
  94.     }
  95.     //cout << "d\n";
  96.     S = stoi(SS);
  97.     N = stoi(SN);
  98.     //cout << "data = " << data << "\n";
  99.     //cout << "N S = " << N <<  ' '<< S << "\n";
  100.  
  101.  
  102.     for (int k = 0; k < N; ++k) {
  103.         getline(file, data);
  104.         char tp;
  105.         int pr, nm;
  106.         string Spr, Snm;
  107.         int i = 0;
  108.         while (data[i] == ' ') {
  109.             i++;
  110.         }
  111.         while (data[i] != ' ') {
  112.             Spr += data[i];
  113.         }
  114.         while (data[i] == ' ') {
  115.             i++;
  116.         }
  117.         while (data[i] != ' ' ) {
  118.             Snm += data[i];
  119.         }
  120.         while (data[i] == ' ') {
  121.             i++;
  122.         }
  123.         tp = data[i];
  124.         pr = stoi(Spr);
  125.         nm = stoi(Snm);
  126.         if (tp == 'A') {
  127.             A.push_back({pr, nm});
  128.         } else {
  129.             B.push_back({pr, nm});
  130.         }
  131.     }
  132.     pii x = f(A, S);
  133.     S = x.second;
  134.     pii y = f(B, S);
  135.     int ans = y.first;
  136.     S = y.second;
  137.     cout << ans << ' ' << S << "\n";
  138. }
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement