fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define endl '\n'
  4. #define name "GDARTS"
  5. #define forw(i, a, b) for (int i = a; i <= b; ++i)
  6. #define fors(i, a, b) for (int i = a; i >= b; --i)
  7. using namespace std;
  8. const int N = 1e3;
  9.  
  10. template <class X, class Y>
  11. bool maximize(X &x, const Y &y)
  12. {
  13. return x < y ? x = y, true : false;
  14. }
  15.  
  16. int n, m;
  17. ll a[N + 5], ans = 0;
  18. int main()
  19. {
  20. ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  21. if (fopen(name".INP", "r"))
  22. {
  23. freopen(name".INP", "r", stdin);
  24. freopen(name".OUT", "w", stdout);
  25. }
  26.  
  27. cin >> n >> m;
  28. forw (i, 1, n) cin >> a[i];
  29.  
  30. sort(a + 1, a + n + 1);
  31. fors (i, n, 1)
  32. ans += a[i] * ((m - ans) / a[i]);
  33.  
  34. cout << ans << endl;
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5332KB
stdin
4 50
3 14 15 9
stdout
48