Advertisement
George_s93

06.TruckTour

Jun 27th, 2025
117
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | Help | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int runCheck(queue<int> FuelC, queue<int> Distance){
  10.     vector<int> fuelVec;
  11.     vector<int> distanceVec;
  12.  
  13.     while (!FuelC.empty() && !Distance.empty()){
  14.         fuelVec.push_back(FuelC.front());
  15.         distanceVec.push_back(Distance.front());
  16.         FuelC.pop();
  17.         Distance.pop();
  18.     }
  19.  
  20.     int n = fuelVec.size();
  21.  
  22.     int totalFuelBalance = 0;
  23.     int currentTankFuel = 0;
  24.     int startStationIndex = 0;
  25.  
  26.      for (int i = 0; i < n; ++i) {
  27.         int netFuelAtStation = fuelVec[i] - distanceVec[i];
  28.  
  29.         totalFuelBalance += netFuelAtStation;
  30.         currentTankFuel += netFuelAtStation;
  31.  
  32.         if (currentTankFuel < 0) {
  33.             currentTankFuel = 0;
  34.             startStationIndex = i + 1;
  35.         }
  36.     }
  37.     return startStationIndex;
  38. }
  39.  
  40. int main(void)
  41. {
  42.     int N;
  43.     cin >> N;
  44.  
  45.     queue<int> PSFuelCap;
  46.     queue<int> PSDistance;
  47.  
  48.     while(N--){
  49.         int tmpF, tmpD;
  50.         cin >> tmpF >> tmpD;
  51.  
  52.         PSFuelCap.push(tmpF);
  53.         PSDistance.push(tmpD);
  54.     }
  55.  
  56.     cout << runCheck(PSFuelCap, PSFuelCap) << endl;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement