-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVasya-the-Hipster.c
39 lines (32 loc) · 1 KB
/
Vasya-the-Hipster.c
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
#include <stdio.h>
int main()
{
int numberOfRedShocks, numberOfBlueShocks,
daysWithDifferentShocks, daysWithSameShocks = 0, numberOfSameShocks;
scanf("%d %d", &numberOfRedShocks, &numberOfBlueShocks);
if (numberOfRedShocks == numberOfBlueShocks)
{
daysWithDifferentShocks = numberOfRedShocks;
}
else
{
if (numberOfRedShocks > numberOfBlueShocks)
{
daysWithDifferentShocks = numberOfBlueShocks;
numberOfSameShocks = numberOfRedShocks - numberOfBlueShocks;
}
if (numberOfRedShocks < numberOfBlueShocks)
{
daysWithDifferentShocks = numberOfRedShocks;
numberOfSameShocks = numberOfBlueShocks - numberOfRedShocks;
}
while (numberOfSameShocks > 1)
{
daysWithSameShocks += 1;
numberOfSameShocks -= 2;
}
}
printf("%d %d", daysWithDifferentShocks, daysWithSameShocks);
return 0;
}
//time-complexity: worst -> O(n/2), best -> O(1)