Advertisement
Guest User

C

a guest
Sep 25th, 2017
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pii pair<int, int>
  3. #define endl '\n'
  4. #define pb push_back
  5. #define lli long long int
  6. #define mod 1000000007
  7.  
  8. using namespace std;
  9. int main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(NULL);
  13.     cout.tie(NULL);
  14.     bool chk=true;
  15.     lli fin, tank, gas, cnt, time=0, now, i;
  16.     cin >> fin >> tank >> gas >> cnt;now=tank;
  17.     for(i=1;i<=cnt;i++)
  18.     {
  19.         if(i==cnt && now>=fin) continue;
  20.         if(chk)
  21.         {
  22.             if(now < gas) cout<<"-1", exit(0);
  23.             if(fin+(fin-gas) <= now) now-=fin;
  24.             else now=tank-(fin-gas), time++;
  25.             chk=false;
  26.         }
  27.         else
  28.         {
  29.             if(now < fin-gas) cout<<"-1", exit(0);
  30.             if(fin+gas <= now) now-=fin;
  31.             else now=tank-gas, time++;
  32.             chk=true;
  33.         }
  34.     }
  35.     cout<<time<<endl;
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement