-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem5.java
More file actions
59 lines (51 loc) · 1.14 KB
/
Problem5.java
File metadata and controls
59 lines (51 loc) · 1.14 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
import java.util.*;
import java.lang.*;
import java.io.*;
public class Problem5
{
static class Bale {
int w;
boolean left;
Bale(int weight, boolean L) {
w = weight;
left = L;
}
}
static class Comp implements Comparator<Bale>
{
public int compare(Bale a, Bale b) {
if (a.w < b.w) {
return -1;
}
else if (a.w == b.w) {
if (a.left) return -1;
}
return 1;
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
int N, M;
N = scan.nextInt();
M = scan.nextInt();
Bale[] bales = new Bale[2 * N];
for (int i = 0; i < N; i++) {
int leftStack = scan.nextInt();
int rightStack = scan.nextInt();
bales[i * 2] = new Bale(leftStack, true);
bales[i * 2 + 1] = new Bale(rightStack, false);
}
Arrays.sort(bales, new Comp());
int L = 0, R = 0;
int i = 0;
while(M - bales[i].w >= 0) {
M -= bales[i].w;
if (bales[i].left) L++;
else R++;
i++;
}
System.out.println((L + R));
System.out.println(L + " " + R);
}
}