fork download
  1. #include <bits/stdc++.h>
  2. #define maxn 10e9+7
  3.  
  4. using namespace std;
  5.  
  6. long long L = 0, R = 0;
  7. long long G = 0;
  8. char s;
  9. int a, kq = 0;
  10.  
  11. int main()
  12. {
  13. while(cin >> s)
  14. {
  15. cin >> a;
  16. if (s == 'L')
  17. {
  18. G -= a;
  19. if (G < L)
  20. kq += L - G, L = G;
  21. }
  22. if (s == 'R')
  23. {
  24. G += a;
  25. if (G > R)
  26. kq += G - R, R = G;
  27. }
  28. }
  29. cout << kq;
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 2732KB
stdin
Standard input is empty
stdout
Standard output is empty