Codeforces Round #436 (Div. 2), problem: (C) Bus Solution In C/C++

By |2017-09-26T16:36:31+00:00September 26th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include <bits/stdc++.h> using namespace std; int main(){ int k,sum=0,end,cap,f,tank; for(cin>>end>>cap>>f>>k,tank=cap;k--;f=end-f) if(tank<f||cap<end-f) return cout<<-1,0; else if(tank>=end+(k?end-f:0)) tank-=end; else ++sum,tank=cap-(end-f); cout<<sum; }