Source code for submission s764

ants.cpp

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8. int L, A;
  9. while(cin >> L >> A){
  10. vector<int> all;
  11. vector<int> left, right;
  12. for(int i=0; i<A; ++i){
  13. int x;
  14. char c;
  15. cin >> x >> c;
  16. all.push_back(x);
  17. if(c == 'L') left.push_back(x);
  18. else right.push_back(x);
  19. }
  20.  
  21. sort(all.begin(), all.end());
  22.  
  23. int min_right = L+1, max_left = -1;
  24. if(right.size() > 0) min_right = *min_element(right.begin(), right.end());
  25. if(left.size() > 0) max_left = *max_element(left.begin(), left.end());
  26.  
  27. int ret = max(L-min_right, max_left);
  28.  
  29. if(L - min_right > max_left){
  30. int len = right.size();
  31. cout << "The last ant will fall down in " << ret << " seconds - started at " << all[all.size() - len] << "." << '\n';
  32. }
  33. else if(L-min_right<max_left){
  34. int len = left.size();
  35. cout << "The last ant will fall down in " << ret << " seconds - started at " << all[len - 1] << "." << '\n';
  36. }
  37. else{
  38. int len = left.size();
  39. //cout << all[len-1] << " " << all[len] << '\n';
  40. cout << "The last ant will fall down in " << ret << " seconds - started at " << all[len - 1] << " and " << all[len] << "." << '\n';
  41. }
  42. }
  43. return 0;
  44. }
  45.  
  46.