Advertisement
Giatro

Soma (OBI 2019)

May 3rd, 2020
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef long double lld;
  7. typedef pair<ll, ll> pll;
  8. typedef vector<ll> vl;
  9. typedef vector<int> vi;
  10. typedef pair<int, int> pii;
  11. typedef vector<pii> vii;
  12.  
  13. #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  14.  
  15. #define fr(i, n) for (ll i = 0; i < n; i++)
  16. #define frr(i, n) for (ll i = 1; i <= n; i++)
  17. #define frd(i, n) for (ll i = n; i >= 0; i--)
  18. #define forita(it, c) for(auto it = c.begin(); it != c.end(); it++)
  19.  
  20. #define sortvector(v) sort(v.begin(), v.end())
  21. #define sortvectorby(v, f) sort(v.begin(), v.end(), f)
  22.  
  23. #define pb push_back
  24. #define mk make_pair
  25. #define f first
  26. #define s second
  27.  
  28. #define cout1e(a) cout << (a) << endl
  29. #define cout2e(a, b) cout << (a) << " " << (b) << endl
  30. #define cout3e(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
  31. #define cout4e(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
  32. #define debug(x) cout << #x << " = " << x << endl
  33. #define get1(a) cin >> (a)
  34. #define get2(a, b) cin >> (a) >> (b)
  35. #define get3(a, b, c) cin >> (a) >> (b) >> (c)
  36. #define get4(a, b, c, d) cin >> (a) >> (b) >> (c) >> (d)
  37.  
  38. const int INF = 0x3f3f3f3f;
  39. const ll LINF = 0x3f3f3f3f3f3f3f;
  40. const ll M = 1000000007;
  41. // ===================================================== //
  42.  
  43. int n, k;
  44. int tot;
  45. int sum;
  46. int lz, rz;
  47. int x;
  48.  
  49. int main(int argc, char const *argv[]) { fastio;
  50.   cin >> n >> k;
  51.   tot = 0;
  52.   sum = 0;
  53.   lz = rz = 0;
  54.  
  55.   fr (i, n) {
  56.     cin >> x;
  57.  
  58.     //cout << "Lendo " << x << ":" << endl;
  59.     //debug(lz); debug(rz); debug(sum); debug(tot);
  60.     //cout << endl;    
  61.  
  62.     if (sum + x > k) {
  63.       if (sum == k) {
  64.         if (k == 0) tot += (lz+1)*lz/2;
  65.         else tot += (rz+1)*(lz+1);
  66.       }
  67.  
  68.       sum = (x > k) ? 0 : x;
  69.       lz = rz = 0;
  70.       if (x == 0) lz++;
  71.  
  72.     } else {
  73.       sum += x;
  74.       if (x == 0) {
  75.         if (sum == 0) lz++;
  76.         if (sum == k) rz++;
  77.       }
  78.     }
  79.   }
  80.  
  81.   if (sum == k) {
  82.     if (k == 0) tot += (lz+1)*lz/2;
  83.     else tot += (rz+1)*(lz+1);
  84.   }
  85.  
  86.   cout1e(tot);
  87.  
  88.   return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement