-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.txt
84 lines (53 loc) · 1.99 KB
/
test.txt
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in = new Scanner(System.in);
int c = in.nextInt();
for(int i = 0;i<c;i++){
int B = in.nextInt();
int L = in.nextInt();
int[][] items = new int[L][2];
int[] m = new int[L];
int[] temp = new int[L];
boolean first = true;
int[] index = new int[L];
int count =0;
int test = 0;
for(int k = 0;k<L;k++){
items[k][0] = in.nextInt();
items[k][1] = in.nextInt();
}
for(int k = L-1;k>=0;k--){
count=1;
m[k] = items[k][0];
int total = items[k][1];
for(int h = L-1;h>=0;h--){
if(items[k][0]==items[h][0]){
continue;
}
if( total <= B){
total += items[h][1];
m[h] = items[h][0];
count+=1;
} else {
if(count > test){
temp = m;
test = count;
}
total = 0;
m = new int[L];
}
}
}
System.out.println(Arrays.toString(temp));
// display
}
}
}