Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define F first
  5. #define S second
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define ld long double
  9. #define endl '\n'
  10. #define TIME 1.0*clock()/CLOCKS_PER_SEC
  11. #define pii pair < int , int >
  12. #define Endl '\n'
  13.  
  14. #pragma GCC optimize("Ofast")
  15. #define int long long
  16. using namespace std;
  17.  
  18. const ll mod = 1e9 + 7;
  19. const int FFTM = 998244353;
  20. const int N = 1e6 + 3;
  21.  
  22. const int SX[4] = {0 , 1 , -1 , 0};
  23. const int SY[4] = {1 , 0 , 0 , -1};
  24. const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
  25. const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};
  26. const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
  27. const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
  28. main() {
  29. ios_base::sync_with_stdio(0);
  30. cin.tie(0);
  31. cout.tie(0);
  32. #ifdef LOCAL
  33. freopen("input.txt", "r", stdin);
  34. freopen("output.txt", "w", stdout);
  35. #else
  36. // freopen("input.txt", "r", stdin);
  37. // freopen("output.txt", "w", stdout);
  38. #endif
  39. int n,h;
  40.  
  41. cin>>n>>h;
  42.  
  43. int cur=1,cur2=h,minc=1e18,maxc2=0;
  44.  
  45. for(int i=0;i<n;i++){
  46. char u;int x;
  47. cin>>u>>x;
  48.  
  49. if(u=='u'){
  50. cur+=x;
  51. cur2+=x;
  52. minc=min(cur,minc);
  53. maxc2=max(cur2,maxc2);
  54. }
  55. else{
  56. cur-=x;
  57. cur2-=x;
  58. minc=min(cur,minc);
  59. maxc2=max(cur2,maxc2);
  60. }
  61. }
  62.  
  63. //cout<<minc<<' '<<maxc2<<endl;
  64.  
  65. int ans=1,ans2=h;
  66.  
  67. if(minc<1){
  68. ans+=ans-minc;
  69. }
  70. if(maxc2>n){
  71. ans2-=maxc2-ans2;
  72. }
  73.  
  74.  
  75. if(ans>ans2){
  76. cout<<0<<endl;
  77. }
  78. else{
  79. cout<<ans2-ans+1<<endl;
  80. }
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement