tuki2501

So23_Bai1.cpp

Nov 1st, 2021
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   cin.tie(0)->sync_with_stdio(0);
  6.   int n, k;
  7.   cin >> n >> k;
  8.   vector<int> a(n + 1), s(n + 1);
  9.   for (int i = 1; i <= n; i++) {
  10.     cin >> a[i];
  11.     s[i] = a[i] + s[i - 1];
  12.   }
  13.   long long ans = 0;
  14.   map<int,int> mem;
  15.   for (int i = 1; i <= n; i++) {
  16.     mem[s[i - 1]]++;
  17.     ans += mem[s[i] - k];
  18.   }
  19.   cout << ans << '\n';
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment