fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. bool prime (ll n) {
  6. ll sqr = sqrt(n);
  7. for (ll i=2; i<=sqr; i++) {
  8. if (n % i == 0) return 0;
  9. }
  10. return 1;
  11. }
  12. ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
  13. ll a[10001]; ll b[10001];
  14. map<char,ll> c;
  15. map<char,ll>:: iterator it;
  16.  
  17. int main()
  18. {
  19. fast();
  20. ll n,sum;
  21. cin>>n>>sum;
  22. vector<ll> V;
  23. V.push_back(1);
  24. ll ck=1;
  25. for(ll i=1;i<=n;i++)
  26. {
  27. ll x; cin>>x;
  28. V.push_back(ck*x);
  29. ck=ck*x;
  30. }
  31. ll ans=0;
  32. for(ll i=V.size()-1;i>=0;i--)
  33. {
  34. if(V[i]>sum) continue;
  35. else
  36. {
  37. ll p=sum/V[i];
  38. ans+=p;
  39. sum-=(p*V[i]);
  40. }
  41. if(sum==0) break;
  42.  
  43. }
  44. cout<<ans;
  45. return 0;
  46. }
  47.  
Runtime error #stdin #stdout #stderr 1.26s 528896KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc