Skip to content

Commit 59ae483

Browse files
authored
Merge pull request #50 from AlgorithmWithGod/khj20006
[20250206] BOJ / 골드2 / 기업투자 / 권혁준
2 parents badf30a + 602a351 commit 59ae483

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
20+
static int N, M;
21+
static int[][] A;
22+
static int[] D;
23+
static int[][] R;
24+
25+
public static void main(String[] args) throws Exception {
26+
27+
ready();
28+
solve();
29+
30+
bwEnd();
31+
}
32+
33+
static void ready() throws Exception{
34+
35+
nextLine();
36+
N = nextInt();
37+
M = nextInt();
38+
A = new int[N+1][M+1];
39+
D = new int[N+1];
40+
R = new int[N+1][N+1];
41+
42+
for(int i=1;i<=N;i++) {
43+
nextLine();
44+
nextInt();
45+
for(int j=1;j<=M;j++) A[i][j] = nextInt();
46+
}
47+
48+
}
49+
50+
static void solve() throws Exception{
51+
52+
for(int i=1;i<=M;i++) {
53+
int[] ND = new int[N+1];
54+
int[][] NR = new int[N+1][N+1];
55+
for(int n=1;n<=N;n++) {
56+
ND[n] = A[n][i];
57+
NR[n][i] = n;
58+
for(int k=1;k<n;k++) {
59+
int res = D[k] + A[n-k][i];
60+
if(res > ND[n]) {
61+
ND[n] = res;
62+
for(int j=1;j<i;j++) NR[n][j] = R[k][j];
63+
NR[n][i] = n-k;
64+
}
65+
}
66+
}
67+
for(int n=1;n<=N;n++) {
68+
if(ND[n] > D[n]) {
69+
D[n] = ND[n];
70+
R[n] = NR[n];
71+
}
72+
}
73+
}
74+
75+
bw.write(D[N] + "\n");
76+
for(int i=1;i<=M;i++) bw.write(R[N][i] + " ");
77+
78+
}
79+
80+
81+
}
82+
83+
```

0 commit comments

Comments
 (0)