Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define pii pair<int, int>
- #define endl '\n'
- #define pb push_back
- #define lli long long int
- #define mod 1000000007
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- bool chk=true;
- lli fin, tank, gas, cnt, time=0, now, i;
- cin >> fin >> tank >> gas >> cnt;now=tank;
- for(i=1;i<=cnt;i++)
- {
- if(i==cnt && now>=fin) continue;
- if(chk)
- {
- if(now < gas) cout<<"-1", exit(0);
- if(fin+(fin-gas) <= now) now-=fin;
- else now=tank-(fin-gas), time++;
- chk=false;
- }
- else
- {
- if(now < fin-gas) cout<<"-1", exit(0);
- if(fin+gas <= now) now-=fin;
- else now=tank-gas, time++;
- chk=true;
- }
- }
- cout<<time<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement