fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 2e5 + 5;
  5. using ll = long long;
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  9. ll n, tar;
  10. cin >> n >> tar;
  11. vector<ll> v(n);
  12. for (int i = 0; i < n; ++i) {
  13. cin >> v[i];
  14. }
  15. int l = 0, r = 0;
  16. ll sum = 0, ans = 0;
  17. while (l < n) {
  18. while (r < n && sum + v[r] <= tar)
  19. sum += v[r], r++;
  20. if (sum == tar)
  21. ans++;
  22. sum -= v[l];
  23. l++;
  24. }
  25. cout << ans << '\n';
  26. return 0;
  27. }
Runtime error #stdin #stdout #stderr 0.01s 5392KB
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