ants.cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int L, A;
while(cin >> L >> A){
vector<int> all;
vector<int> left, right;
for(int i=0; i<A; ++i){
int x;
char c;
cin >> x >> c;
all.push_back(x);
if(c == 'L') left.push_back(x);
else right.push_back(x);
}
sort(all.begin(), all.end());
int min_right = L+1, max_left = -1;
if(right.size() > 0) min_right = *min_element(right.begin(), right.end());
if(left.size() > 0) max_left = *max_element(left.begin(), left.end());
int ret = max(L-min_right, max_left);
if(L - min_right > max_left){
int len = right.size();
cout << "The last ant will fall down in " << ret << " seconds - started at " << all[all.size() - len] << "." << '\n';
}
else if(L-min_right<max_left){
int len = left.size();
cout << "The last ant will fall down in " << ret << " seconds - started at " << all[len - 1] << "." << '\n';
}
else{
int len = left.size();
//cout << all[len-1] << " " << all[len] << '\n';
cout << "The last ant will fall down in " << ret << " seconds - started at " << all[len - 1] << " and " << all[len] << "." << '\n';
}
}
return 0;
}