-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (43 loc) · 1.04 KB
/
Main.java
File metadata and controls
45 lines (43 loc) · 1.04 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
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
int[][] count = new int[m][2];
int[] max = new int[m+1];
for(int i=0;i<m;i++)
{
count[i][0] = scanner.nextInt();
count[i][1] = 0;
max[i] = 0;
}
for (int i = 0; i < m; i++)
{
for (int j = 1; j <= m; j++)
{
if (max[j] + count[i][0] <= 100)
{
max[j] += count[i][0];
count[i][1] = j;
break;
}
}
}
int temp=1;
for(int i=0;i<m;i++)
{
if (count[i][1] > temp)
{
temp = count[i][1];
}
}
for(int i=0;i<m;i++)
{
System.out.println(count[i][0] + " " + count[i][1]);
}
System.out.println(temp);
}
}