georgiy110802

Untitled

Jun 15th, 2021
535
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. ll n, k, ans = 0;
  8. const int maxn = 100005;
  9. ll vv[maxn], p[maxn];
  10.  
  11. void input() {
  12.     cin >> n >> k;
  13.     for (ll i = 0; i < n; ++i) {
  14.         cin >> vv[i];
  15.     }
  16. }
  17.  
  18. void solve() {
  19.     for (ll i = 1; i < n + 10; ++i) {
  20.         p[i] = p[i - 1] + vv[i - 1];
  21.     }
  22.     ll it1 = 0, it2 = 0 ;
  23.     while (it2 < n + 10) {
  24.         if (p[it2] - p[it1] >= k) {
  25.             if (p[it2] - p[it1] == k)
  26.                 ans++;
  27.             ++it1;
  28.         } else ++it2;
  29.     }
  30. }
  31.  
  32. int main() {
  33.     input();
  34.     solve();
  35.     cout << ans << endl;
  36. }
RAW Paste Data