Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- #include <fstream>
- pii f(vector <pii> a, int S) {
- sort(a.begin(), a.end());
- int n = a.size();
- int res = 0;
- for (int i = 0; i < n; ++i) {
- while (S - a[i].first >= 0 && a[i].second - 1 >= 0) {
- S -= a[i].first;
- a[i].second--;
- res++;
- }
- }
- return {res, S};
- }
- int main() {
- string data;
- ifstream file("26.txt");
- vector <pii> a, b;
- vector <pii> A, B;
- getline(file, data);
- int S, N;
- string SN, SS;
- int i = 0;
- while (data[i] == ' ' ) {
- i++;
- }
- //cout << "a\n";
- while (data[i] != ' ') {
- SN += data[i];
- i++;
- }
- //cout << "b\n";
- while (data[i] == ' ') {
- i++;
- }
- //cout << "c\n";
- //cout << "data = " << data << "\n";
- while (i < data.size() && data[i] != ' ' ) {
- SS += data[i];
- i++;
- }
- //cout << "d\n";
- S = stoi(SS);
- N = stoi(SN);
- //cout << "data = " << data << "\n";
- //cout << "N S = " << N << ' '<< S << "\n";
- for (int k = 0; k < N; ++k) {
- getline(file, data);
- char tp;
- int pr, nm;
- string Spr, Snm;
- int i = 0;
- while (data[i] == ' ') {
- i++;
- }
- while (data[i] != ' ') {
- Spr += data[i];
- }
- while (data[i] == ' ') {
- i++;
- }
- while (data[i] != ' ' ) {
- Snm += data[i];
- }
- while (data[i] == ' ') {
- i++;
- }
- tp = data[i];
- pr = stoi(Spr);
- nm = stoi(Snm);
- if (tp == 'A') {
- A.push_back({pr, nm});
- } else {
- B.push_back({pr, nm});
- }
- }
- pii x = f(A, S);
- S = x.second;
- pii y = f(B, S);
- int ans = y.first;
- S = y.second;
- cout << ans << ' ' << S << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement