fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9.  
  10. int position = 0;
  11.  
  12. for (int i = 0; i < n; ++i) {
  13. int t;
  14. string direction;
  15. cin >> t >> direction;
  16.  
  17. if (direction == "North") {
  18. if (position - t < 0) {
  19. cout << "NO\n";
  20. return 0;
  21. }
  22. position -= t;
  23. } else if (direction == "South") {
  24. if (position + t > 20000) {
  25. cout << "NO\n";
  26. return 0;
  27. }
  28. position += t;
  29. } else { // "West" atau "East"
  30. if (position == 0 || position == 20000) {
  31. cout << "NO\n";
  32. return 0;
  33. }
  34. }
  35. }
  36.  
  37. if (position == 0) {
  38. cout << "YES\n";
  39. } else {
  40. cout << "NO\n";
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 5292KB
stdin
5
7500 South
10000 East
3500 North
4444 West
4000 North
stdout
YES