Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define fi first
- #define se second
- #define mp make_pair
- #define pb push_back
- #define Co_mot_su_that_la return
- using namespace std;
- typedef pair<int,int> ii;
- typedef pair<int,ii> iii;
- typedef vector<int> vi;
- typedef vector<ii> vii;
- typedef vector<vi> vvi;
- typedef vector<iii> viii;
- const int N = 1005;
- int q;
- int n;
- int M;
- int a[N];
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- q = 1;
- while (q--)
- {
- //your code goes here
- cin >> n >> M;
- for(int i=1; i<=n; i++)
- {
- cin >> a[i];
- }
- sort(a+1,a+1+n);
- int i = n;
- int res = 0;
- while (i >= 1)
- {
- if (M >= a[i])
- {
- res += a[i];
- M -= a[i];
- }
- if (M < a[i])
- {
- i--;
- }
- }
- cout << res;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement