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>
- string sN, sM;
- int N,M;
- void f(string data) {
- int i=0;
- while (data[i] == ' ') {
- i++;
- }
- while (data[i] != ' ') {
- sN += data[i];
- i++;
- }
- while (data[i] == ' ') {
- i++;
- }
- while (data[i] != ' ') {
- sM += data[i];
- i++;
- }
- N = stoi(sN);
- M = stoi(sM);
- cout << "N M = " << N << ' ' << M << "\n";
- }
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- string data;
- ifstream file("26.txt");
- vector <int> a;
- int cnt=-1;
- int add = 0;
- int addnum = 0;
- while (getline(file, data)) {
- cnt++;
- if (cnt == 0) {
- f(data);
- //cout << "N M = " << N << ' ' << M << "\n";
- continue;
- }
- //cout << data << "\n";
- int x = stoi(data);
- if (x >= 200 && x <= 210) {
- M -= x;
- add+=x;
- addnum++;
- N--;
- continue;
- }
- a.pb(x);
- //cout << "x = " << x << "\n";
- }
- sort(a.begin(), a.end());
- cout << "N M = " << N << ' ' << M << "\n";
- cout << "a\n";
- cout << "addnum = " << addnum << "\n";
- cout << "add = " << add << "\n";
- cv(a);
- int i = 0;
- ll S = 0;
- int num=0;
- vector <int> our, odd;
- while (i < N && S + a[i] <= M) {
- S += a[i];
- our.pb(a[i]);
- i++;
- num++;
- }
- while (i < N) {
- odd.pb(a[i]);
- i++;
- }
- for (int i = num - 1; i >= 0; --i) {
- for (int j = odd.size() - 1; j >= 0; --j) {
- if (S - our[i] + odd[j] <= M) {
- S = S - our[i] + odd[j];
- int A = our[i], B = odd[j];
- our[i] = B;
- odd[j] = A;
- sort(odd.begin(), odd.end());
- break;
- }
- }
- }
- num += addnum;
- S += add;
- cout << num << ' ' << S;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement