Advertisement
MinhNGUYEN2k4

Untitled

Oct 27th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #define fi first
  4. #define se second
  5. #define mp make_pair
  6. #define pb push_back
  7. #define Co_mot_su_that_la return
  8.  
  9. using namespace std;
  10. typedef pair<int,int> ii;
  11. typedef pair<int,ii> iii;
  12. typedef vector<int> vi;
  13. typedef vector<ii> vii;
  14. typedef vector<vi> vvi;
  15. typedef vector<iii> viii;
  16.  
  17. const int N = 1005;
  18.  
  19. int q;
  20. int n;
  21. int M;
  22. int a[N];
  23.  
  24. signed main()
  25. {
  26.   ios_base::sync_with_stdio(false);
  27.   cin.tie(0);cout.tie(0);
  28.   q = 1;
  29.   while (q--)
  30.   {
  31.     //your code goes here
  32.     cin >> n >> M;
  33.     for(int i=1; i<=n; i++)
  34.     {
  35.         cin >> a[i];
  36.     }
  37.     sort(a+1,a+1+n);
  38.     int i = n;
  39.     int res = 0;
  40.     while (i >= 1)
  41.     {
  42.         if (M >= a[i])
  43.         {
  44.             res += a[i];
  45.             M -= a[i];
  46.         }
  47.         if (M < a[i])
  48.         {
  49.             i--;
  50.         }
  51.     }
  52.     cout << res;
  53.   }
  54.   return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement