Advertisement
askarulytarlan

Untitled

Oct 4th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a, b, f, k, now, c;
  6.  
  7. int main(){
  8. cin >> a >> b >> f >> k;
  9. now = b;
  10. for(int i = 0; i < k; i++){
  11. if(i & 1){
  12. now -= (a-f);
  13. if(now < 0){
  14. cout << -1;
  15. return 0;
  16. }
  17. else{
  18. if(i == k - 1){
  19. if(a - f > now){
  20. now = b;
  21. c++;
  22. }
  23. }
  24. else if((f) * 2 > now){
  25. if((f) * 2 > b){
  26. cout << -1;
  27. return 0;
  28. }
  29. else{
  30. now = b;
  31. c++;
  32. }
  33. }
  34. }
  35. now -= (f);
  36. }
  37. else{
  38. now -= f;
  39. if(now < 0){
  40. cout << -1;
  41. return 0;
  42. }
  43. else{
  44. if(i == k - 1){
  45. if(a - f > now){
  46. now = b;
  47. c++;
  48. }
  49. }
  50. else if((a - f) * 2 > now){
  51. if((a - f) * 2 > b){
  52. cout << -1;
  53. return 0;
  54. }
  55. else{
  56. now = b;
  57. c++;
  58. }
  59. }
  60. now -= (a - f);
  61. }
  62. }
  63. }
  64. cout << c;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement