-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
53 lines (46 loc) · 1.05 KB
/
Copy pathB.cpp
File metadata and controls
53 lines (46 loc) · 1.05 KB
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
51
52
53
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repx(i, a, n) for(int i = a; i < n; i++)
#define eb emplace_back
int main()
{
ll d,m,d1,n,d2;
cin >> d >> m >> d1 >> n >> d2;
ll friend_counter = 0;
while(true)
{
// si es que recibio el libro
if (d <= 0)
{
cout << friend_counter << "\n";
break;
}
// si es que no quedan amigos para buscar el libro
if (m == 0 && n == 0)
{
cout << "-1\n";
break;
}
// si es que ninguno de los amigos que quedan me puede llegar al libro
if ( (m > 0 && d1 <= d) || (m == 0 and d2 <= d) )
{
cout << "-1\n";
break;
}
// acercamos el libro
if (m > 0)
{
d -= (d1 - d);
m--;
friend_counter++;
}
else
{
d -= (d2 - d);
n--;
friend_counter++;
}
}
}