Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, k;
- cin >> n >> k;
- int arr[n];
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- long long ans = 0;
- for(int l = 0; l < n; l++) {
- int sum = arr[l];
- if(sum > k) {
- continue;
- }
- for(int r = l; r < n; r++) {
- if(l == r) {
- if(sum == k) {
- ans++;
- }
- continue;
- } else {
- sum += arr[r];
- }
- if(sum > k) {
- break;
- } else if(sum == k) {
- ans++;
- }
- }
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement