[BOJ] 1173 운동

Time Lapse :None

1173.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <algorithm>
using namespace std;
int N, m, M, T, R;
int main(void){
cin>>N>>m>>M>>T>>R;
if(m+T>M){
cout<<"-1"<<endl;
return 0;
}
int cnt=0, stat = m;
do{
if(stat+T<=M){
stat+=T;
--N;
}
else{
stat-=R;
if(stat<m)
stat = m;
}
++cnt;
}while(N);
cout<<cnt<<endl;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1173/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.