Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <queue>
- using namespace std;
- int main() {
- int pumps, fuel, distance;
- cin >> pumps;
- cin.ignore();
- queue<int> 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement