#include #include #include using namespace std; int main() { int pumps, fuel, distance; cin >> pumps; cin.ignore(); queue fuelTankPumps; string pump; for (int i = 0; i < pumps; i++) { getline(cin, pump); fuel = stoi(pump.substr(0, pump.find(' '))); distance = stoi(pump.substr(pump.find(' ') + 1)); fuelTankPumps.push(fuel - distance); } int fuelQuantity = 0, index = 0; for (int i = 0; i < pumps; i++) { fuelQuantity += fuelTankPumps.front(); fuelTankPumps.push(fuelTankPumps.front()); fuelTankPumps.pop(); if (fuelQuantity < 0) { fuelQuantity = 0; index = i + 1; } } cout << index << endl; return 0; }