#include <iostream>
#include <stack>
using namespace std;
//float fuel[] = { 5,3,12,1,7 }; float dist[] = { 8,4,7,4,5 };
float fuel[] = { 3,4,6,3,7,11 }; float dist[] = { 3,10,2,4,6,9 };
int n = 6;
int FindMinimumPosition()
{ float last = 0; int position = 0; float minimumFuel = 1; int minimumPosition = 0;
while (position < n)
{ last += fuel[position];
last -= dist[position];
position++; // could be n which is past array bounds
if (last < minimumFuel)
{ minimumFuel = last; minimumPosition = position % n; //in case of last station
}
}
return minimumPosition ;
}
int main(){
cout<< FindMinimumPosition();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RhY2s+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovL2Zsb2F0IGZ1ZWxbXSA9IHsgNSwzLDEyLDEsNyB9OyBmbG9hdCBkaXN0W10gPSB7IDgsNCw3LDQsNSB9OyAKZmxvYXQgZnVlbFtdID0geyAzLDQsNiwzLDcsMTEgfTsgZmxvYXQgZGlzdFtdID0geyAzLDEwLDIsNCw2LDkgfTsgCmludCBuID0gNjsgCmludCBGaW5kTWluaW11bVBvc2l0aW9uKCkgCnsgZmxvYXQgbGFzdCA9IDA7IGludCBwb3NpdGlvbiA9IDA7IGZsb2F0IG1pbmltdW1GdWVsID0gMTsgaW50IG1pbmltdW1Qb3NpdGlvbiA9IDA7IAp3aGlsZSAocG9zaXRpb24gPCBuKSAKeyBsYXN0ICs9IGZ1ZWxbcG9zaXRpb25dOyAKbGFzdCAtPSBkaXN0W3Bvc2l0aW9uXTsgCnBvc2l0aW9uKys7IC8vIGNvdWxkIGJlIG4gd2hpY2ggaXMgcGFzdCBhcnJheSBib3VuZHMgCmlmIChsYXN0IDwgbWluaW11bUZ1ZWwpIAp7IG1pbmltdW1GdWVsID0gbGFzdDsgbWluaW11bVBvc2l0aW9uID0gcG9zaXRpb24gJSBuOyAvL2luIGNhc2Ugb2YgbGFzdCBzdGF0aW9uIAp9IAp9IApyZXR1cm4gbWluaW11bVBvc2l0aW9uIDsKfQppbnQgbWFpbigpewoJY291dDw8IEZpbmRNaW5pbXVtUG9zaXRpb24oKTsKfQ==