Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <climits>
- #include <queue>
- #include <string>
- #include <vector>
- #include <sstream>
- using namespace std;
- bool canFinishTour(queue<int> amounts,queue<int> distances)
- {
- int reservoir = 0;
- while(amounts.size())
- {
- reservoir += amounts.front();
- int distanceToNext = distances.front();
- if(reservoir >= distanceToNext)
- {
- reservoir -= distanceToNext;
- }else{
- return false;
- }
- distances.pop();
- amounts.pop();
- }
- return true;
- }
- int main()
- {
- queue<int> distances;
- queue<int> amounts;
- int numberOfStation;
- cin >> numberOfStation;
- for(int i = 0; i < numberOfStation; i++)
- {
- int buf;
- cin >> buf;
- amounts.push(buf);
- cin >> buf;
- distances.push(buf);
- }
- int curStationStart;
- for(curStationStart = 0; curStationStart < numberOfStation; curStationStart++)
- {
- if(canFinishTour(amounts, distances))
- break;
- int distance = distances.front();
- int amount = amounts.front();
- distances.pop(); amounts.pop();
- distances.push(distance);
- amounts.push(amount);
- }
- cout << curStationStart << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement