You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
bapc-prelim-2015/bapc-e.cpp

36 lines
720 B

#include <iostream>
#include <stack>
#include <cmath>
int main(int argc, char const *argv[])
{
int T;
std::cin >> T;
for (int i = 0; i < T; ++i)
{
int N;
std::cin >> N;
int minimum = 0;
int min_delta_g = 0x7FFFFFFF;
int delta_g = 0;
for(int j = 0; j < N; j++) {
int G,D;
std::cin >> G;
std::cin >> D;
delta_g += G - D;
//std::cout << "station " << j << " delta_g: " << delta_g << " minimum:" << min_delta_g << " (id: " << minimum << ")" << std::endl;
if (delta_g < min_delta_g) {
minimum = j;
min_delta_g = delta_g;
}
}
if (delta_g < 0) {
std::cout << "IMPOSSIBLE" << std::endl;
} else {
std::cout << (((minimum + 1) % N) + 1) << std::endl;
}
}
return 0;
}