-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhayfeast.java
More file actions
66 lines (60 loc) · 1.46 KB
/
hayfeast.java
File metadata and controls
66 lines (60 loc) · 1.46 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
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.*;
import java.util.*;
public class hayfeast {
public static long getMinValue(long[] numbers){
long minValue = numbers[0];
for(int i=1;i<numbers.length;i++){
if(numbers[i] < minValue){
minValue = numbers[i];
}
}
return minValue;
}
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(new File("hayfeast.in"));
PrintWriter pw = new PrintWriter(new File("hayfeast.out"));
int n = sc.nextInt();
long minFlavor = sc.nextLong();
long[][] haybales = new long[n][2];
for(int i = 0; i<n; i++) {
haybales[i][0]=sc.nextLong();
haybales[i][1]=sc.nextLong();
}
long maxSpice = 0;
long[] spices = new long[n];
long totalFlavor=0;
int i = 0;
for(int k = 0; k<n; k++) {
spices[k]=0;
}
for(int start = 0; start<n; start++) {
while(i<n && totalFlavor<minFlavor) {
totalFlavor += haybales[i][0];
if(haybales[i][1]>maxSpice) {
maxSpice=haybales[i][1];
}
i++;
}
if(totalFlavor<minFlavor) {
for(int j = start; j<n; j++) {
spices[j]=1000000001;
}
break;
}
else {
spices[start]=maxSpice;
}
totalFlavor-=haybales[start][0];
if(haybales[start][1]==maxSpice) {
maxSpice=0;
for(int k = start+1; k<=i; k++) {
if(haybales[k][1]>maxSpice) {
maxSpice=haybales[k][1];
}
}
}
}
pw.println(getMinValue(spices));
pw.close();
}
}