include iostream include cmath include algorithm using namespace std i

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n,
t1,
t2,
time1 = 0,
time2 = 0,
count = 0;
cin >> n >> t1 >> t2;
int mint = min(t1, t2);
int maxt = max(t1, t2);
t2 = maxt; t1 = mint;
int nakop = 0;
bool f = false;
while (n > 0) {
if (maxt > 0) {
maxt -= mint;
time1 += mint;
count++;
n--;
}
if (maxt <= 0) {
if (maxt < 0) {
f = true;
time2 = maxt + t2;
}
else
f = false;
maxt += t2;
n--;
count++;
if (f && n == 0) {
count++;
time1 += time2;
}
}
}
cout << count << " " << time1 << endl;
return 0;
}