Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- typedef unsigned long long int ull;
- typedef long double lld;
- typedef pair<ll, ll> pll;
- typedef vector<ll> vl;
- typedef vector<int> vi;
- typedef pair<int, int> pii;
- typedef vector<pii> vii;
- #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
- #define fr(i, n) for (ll i = 0; i < n; i++)
- #define frr(i, n) for (ll i = 1; i <= n; i++)
- #define frd(i, n) for (ll i = n; i >= 0; i--)
- #define forita(it, c) for(auto it = c.begin(); it != c.end(); it++)
- #define sortvector(v) sort(v.begin(), v.end())
- #define sortvectorby(v, f) sort(v.begin(), v.end(), f)
- #define pb push_back
- #define mk make_pair
- #define f first
- #define s second
- #define cout1e(a) cout << (a) << endl
- #define cout2e(a, b) cout << (a) << " " << (b) << endl
- #define cout3e(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
- #define cout4e(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
- #define debug(x) cout << #x << " = " << x << endl
- #define get1(a) cin >> (a)
- #define get2(a, b) cin >> (a) >> (b)
- #define get3(a, b, c) cin >> (a) >> (b) >> (c)
- #define get4(a, b, c, d) cin >> (a) >> (b) >> (c) >> (d)
- const int INF = 0x3f3f3f3f;
- const ll LINF = 0x3f3f3f3f3f3f3f;
- const ll M = 1000000007;
- // ===================================================== //
- int n, k;
- int tot;
- int sum;
- int lz, rz;
- int x;
- int main(int argc, char const *argv[]) { fastio;
- cin >> n >> k;
- tot = 0;
- sum = 0;
- lz = rz = 0;
- fr (i, n) {
- cin >> x;
- //cout << "Lendo " << x << ":" << endl;
- //debug(lz); debug(rz); debug(sum); debug(tot);
- //cout << endl;
- if (sum + x > k) {
- if (sum == k) {
- if (k == 0) tot += (lz+1)*lz/2;
- else tot += (rz+1)*(lz+1);
- }
- sum = (x > k) ? 0 : x;
- lz = rz = 0;
- if (x == 0) lz++;
- } else {
- sum += x;
- if (x == 0) {
- if (sum == 0) lz++;
- if (sum == k) rz++;
- }
- }
- }
- if (sum == k) {
- if (k == 0) tot += (lz+1)*lz/2;
- else tot += (rz+1)*(lz+1);
- }
- cout1e(tot);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement