Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <sstream>
- #include <vector>
- using namespace std;
- int runCheck(queue<int> FuelC, queue<int> Distance){
- vector<int> fuelVec;
- vector<int> distanceVec;
- while (!FuelC.empty() && !Distance.empty()){
- fuelVec.push_back(FuelC.front());
- distanceVec.push_back(Distance.front());
- FuelC.pop();
- Distance.pop();
- }
- int n = fuelVec.size();
- int totalFuelBalance = 0;
- int currentTankFuel = 0;
- int startStationIndex = 0;
- for (int i = 0; i < n; ++i) {
- int netFuelAtStation = fuelVec[i] - distanceVec[i];
- totalFuelBalance += netFuelAtStation;
- currentTankFuel += netFuelAtStation;
- if (currentTankFuel < 0) {
- currentTankFuel = 0;
- startStationIndex = i + 1;
- }
- }
- return startStationIndex;
- }
- int main(void)
- {
- int N;
- cin >> N;
- queue<int> PSFuelCap;
- queue<int> PSDistance;
- while(N--){
- int tmpF, tmpD;
- cin >> tmpF >> tmpD;
- PSFuelCap.push(tmpF);
- PSDistance.push(tmpD);
- }
- cout << runCheck(PSFuelCap, PSFuelCap) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement