Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define F first
- #define S second
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define endl '\n'
- #define TIME 1.0*clock()/CLOCKS_PER_SEC
- #define pii pair < int , int >
- #define Endl '\n'
- #pragma GCC optimize("Ofast")
- #define int long long
- using namespace std;
- const ll mod = 1e9 + 7;
- const int FFTM = 998244353;
- const int N = 1e6 + 3;
- const int SX[4] = {0 , 1 , -1 , 0};
- const int SY[4] = {1 , 0 , 0 , -1};
- const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
- const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};
- const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
- const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
- main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- #endif
- int n,h;
- cin>>n>>h;
- int cur=1,cur2=h,minc=1e18,maxc2=0;
- for(int i=0;i<n;i++){
- char u;int x;
- cin>>u>>x;
- if(u=='u'){
- cur+=x;
- cur2+=x;
- minc=min(cur,minc);
- maxc2=max(cur2,maxc2);
- }
- else{
- cur-=x;
- cur2-=x;
- minc=min(cur,minc);
- maxc2=max(cur2,maxc2);
- }
- }
- //cout<<minc<<' '<<maxc2<<endl;
- int ans=1,ans2=h;
- if(minc<1){
- ans+=ans-minc;
- }
- if(maxc2>n){
- ans2-=maxc2-ans2;
- }
- if(ans>ans2){
- cout<<0<<endl;
- }
- else{
- cout<<ans2-ans+1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement