Advertisement
Spocoman

06. Truck Tour

Jan 16th, 2024 (edited)
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int pumps, fuel, distance;
  9.     cin >> pumps;
  10.     cin.ignore();
  11.  
  12.     queue<int> fuelTankPumps;
  13.  
  14.     string pump;
  15.  
  16.     for (int i = 0; i < pumps; i++) {
  17.         getline(cin, pump);
  18.         fuel = stoi(pump.substr(0, pump.find(' ')));
  19.         distance = stoi(pump.substr(pump.find(' ') + 1));
  20.         fuelTankPumps.push(fuel - distance);
  21.     }
  22.  
  23.     int fuelQuantity = 0, index = 0;
  24.  
  25.     for (int i = 0; i < pumps; i++) {
  26.         fuelQuantity += fuelTankPumps.front();
  27.         fuelTankPumps.push(fuelTankPumps.front());
  28.         fuelTankPumps.pop();
  29.  
  30.         if (fuelQuantity < 0) {
  31.             fuelQuantity = 0;
  32.             index = i + 1;
  33.         }
  34.     }
  35.  
  36.     cout << index << endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement