ants.cpp
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
using namespace std;
int main(){
int L, A;
vector<int> li;
while (cin >> L >> A){
int steps ;
char r;
int rtime = -1,ltime = -1;
char rWin,lWin;
int lefts, rights;
lefts = rights = 0;
li.clear();
for (int i = 0; i < A; i++){
cin >> steps >> r;
li.push_back(steps);
if (r == 'R'){
rights++;
int t= L - steps;
if (rtime < t){
rtime = t;
rWin = r;
}
} else {
lefts++;
int t = steps;
if (ltime < t){
ltime = t;
lWin = r;
}
}
}
sort(li.begin(), li.end());
if (ltime == rtime){ //two winners
cout << "The last ant will fall down in "<< ltime << " seconds - started at " << li[lefts-1] << " and "<<li[A-rights]<< "." << endl;
} else if (ltime > rtime) {
cout << "The last ant will fall down in "<< ltime << " seconds - started at " << li[lefts-1] << "." << endl;
} else {
cout << "The last ant will fall down in "<< rtime << " seconds - started at " << li[A-rights] << "." << endl;
}
}
return 0;
}