-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSoobasaVaDostan.java
More file actions
53 lines (43 loc) · 1.66 KB
/
Copy pathSoobasaVaDostan.java
File metadata and controls
53 lines (43 loc) · 1.66 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
import java.util.Scanner;
/*
Question title = subasa va doostan - سوباسا و دوستان
https://quera.ir/problemset/108669/
*/
public class SoobasaVaDostan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split("\\s");
int countGoal = Integer.parseInt(input[0]);
int firstHalf = Integer.parseInt(input[1]);
int secondHalf = Integer.parseInt(input[2]);
String[] goals = sc.nextLine().split("\\s");
int sum = calculate(goals, firstHalf, secondHalf);
if (sum < countGoal)
System.out.println("NO");
else
System.out.println("YES");
}
// returns sum of goals in first half and second half
private static int calculate(String[] goals, int firstHalf, int secondHalf) {
int firstTimeGoals = 0;
int secondTimeGoals = 0;
boolean done = false;
int previousTimeInFirstHalf = Integer.parseInt(goals[0]);
int previousTimeInSecondHalf = 45;
for (String i : goals) {
int goal = Integer.parseInt(i);
// if the goal is in the first half
if (goal <= 45 + firstHalf && goal >= previousTimeInFirstHalf && !done) {
firstTimeGoals++;
}
// if the goal is in the second half
else if (goal >= 45 && goal <= 90 + secondHalf && goal >= previousTimeInSecondHalf) {
secondTimeGoals++;
done = true;
previousTimeInSecondHalf = goal;
}
previousTimeInFirstHalf = goal;
}
return firstTimeGoals + secondTimeGoals;
}
}