fork download
  1. #include<bits/stdc++.h>
  2. #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. #define ll long long
  4. using namespace std;
  5. int main()
  6. {
  7. faster
  8. ll n,x,i,res=0,l=0,t=0,r;
  9. cin>>n>>x;
  10. vector<ll> a(n);
  11. for(i=0;i<n;i++) cin>>a[i];
  12. for(r=0;r<n;r++)
  13. {
  14. t+=a[r];
  15. while(t>x&&l<=r)
  16. {
  17. t-=a[l];
  18. l++;
  19. }
  20. if(t==x) res++;
  21. }
  22. cout<<res;
  23. }
Success #stdin #stdout 0.01s 5276KB
stdin
5 7
2 4 1 2 7
stdout
3