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);
- }
- 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);
- 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";
- cv(a);
- int i = 0;
- ll S = 0;
- int num=0;
- while (i < N && S + a[i] <= M) {
- S += a[i];
- i++;
- num++;
- }
- int til = num - 1;
- for (int i = N - 1; i >= num; --i) {
- int newS = S - a[til] + a[i];
- if (newS <= M) {
- S = newS;
- }
- }
- S += add;
- num += addnum;
- cout << num << " " << S << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement