fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int MAXN = 200000;
  5. ll a[MAXN];
  6. ll chan[MAXN+3];
  7. ll le[MAXN +3];
  8. ll n , k;
  9. void s(){
  10. ll dem = 0;
  11. for( int i = 1 ; i<n ; i++ ) {
  12. for( int j = i ; j<= n ; j++ ){
  13. ll x = chan[j] - chan[i-1];
  14. ll y = le[j] - le[i-1];
  15. if(0<x && 0 < y && 0 <= x-y && x-y <= k) dem++;
  16. }
  17. }cout << dem;
  18. }
  19. int main(){
  20. ios::sync_with_stdio(false);
  21. cin.tie(nullptr);
  22. freopen("DAYSODEP.INP" , "r" , stdin);
  23. freopen("DAYSODEP.OUT" , "w" , stdout);
  24. cin >> n >> k;
  25. for( int x , i = 1 ; i<= n ; i++ ){
  26. cin >> x;
  27. chan[i] = chan[i-1];
  28. le[i] = le[i-1];
  29. if( x%2 == 0 ) chan[i] += x;
  30. else le[i] += x;
  31. }
  32. s();
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5284KB
stdin
5 5
1 3 2 9 10
stdout
3