Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <bits/stdc++.h>
- #define int long long
- signed main() {
- int n, h;
- char t;
- int x;
- int cur = 0;
- int mx = 0;
- int mn = 0;
- cin >> n >> h;
- for (int i = 0; i < n; ++i) {
- cin >> t >> x;
- if (t == 'u') {
- cur += x;
- mx = max(mx, cur);
- }
- else {
- cur -= x;
- mn = min(mn, cur);
- }
- }
- if (mx - mn + 1 > h) {
- cout << 0;
- }
- else {
- cout << h - mx + mn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement