Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const long long INF = 1e9 + 7;
- const int MAXN = 200 + 10;
- const int N = 1e5 + 10;
- int Sum(int a1, int n, int d) {
- return (2 * a1 + d * (n - 1)) * n / 2;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, s;
- cin >> n >> s;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- int l = 0, sum = 0, ans = 0;
- for (int r = 0; r < n; ++r) {
- sum += a[r];
- while (sum > s && l <= r) {
- sum -= a[l];
- ++l;
- }
- ans += Sum(1, r - l + 1, 1);
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment