fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n,m,no;
  6. string s;
  7. cin>>n>>m;
  8. bool flag;
  9. int lef=n+1,ri=0;
  10. while(m--)
  11. {
  12. flag=false;
  13. for(int i=0;i<4;i++)
  14. {
  15. cin>>s;
  16. //cout<<s<<endl;
  17. if(i==2)
  18. {
  19. if(s=="right")
  20. flag=true;
  21. else
  22. flag=false;
  23. }
  24. }
  25. cin>>no;
  26. if(!flag)//true-->right
  27. {
  28. lef=min(lef,no);
  29. }
  30. else
  31. {
  32. ri=max(ri,no);
  33. }
  34. }
  35. cout<<"left "<<lef<<" ri"<<ri<<endl;
  36. if(lef<ri)
  37. cout<<-1<<endl;
  38. else
  39. cout<<lef-ri-1<<endl;
  40. }
Success #stdin #stdout 0s 4540KB
stdin
3 2
To the right of 1
To the right of 2
stdout
left 4 ri2
1