#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 2010;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
ll n , L , ans[MAXN] , mark[MAXN] , ps[MAXN] , V[MAXN][MAXN];
pll pos[MAXN][MAXN];
int cmp(pll A , pll B){
if(A.X / A.Y != B.X / B.Y) return A.X / A.Y < B.X / B.Y;
A.X %= A.Y; B.X %= B.Y;
return A.X * B.Y < A.Y * B.X;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> L;
for(int i = 1 ; i <= n ; i++){
ll sum = 0;
for(int j = 1 ; j <= L ; j++){
cin >> V[i][j];
sum += V[i][j];
ps[j] = ps[j - 1] + V[i][j] * n;
}
for(int j = 1 ; j <= n ; j++){
int ind = lower_bound(ps , ps + L + 1 , sum * j) - ps;
pos[i][j] = {sum * j - ps[ind - 1] + (ind - 1) * V[i][ind] * n , V[i][ind] * n};
//cout << i << sep << j << sep << pos[i][j].X << sep << pos[i][j].Y << endl;
}
}
for(int i = 1 ; i <= n ; i++){
pll mn = {MOD , 1};
for(int j = 1 ; j <= n ; j++){
if(!mark[j]){
if(cmp(pos[j][i] , mn)){
mn = pos[j][i];
ans[i] = j;
}
}
}
mark[ans[i]] = 1;
if(i != n){
cout << mn.X << sep << mn.Y << endl;
}
}
for(int i = 1 ; i <= n ; i++){
cout << ans[i] << sep;
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
472 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
408 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
408 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
33 ms |
13392 KB |
Output is correct |
44 |
Correct |
214 ms |
63900 KB |
Output is correct |
45 |
Correct |
116 ms |
28796 KB |
Output is correct |
46 |
Correct |
16 ms |
4040 KB |
Output is correct |
47 |
Correct |
156 ms |
42444 KB |
Output is correct |
48 |
Correct |
126 ms |
75596 KB |
Output is correct |
49 |
Correct |
52 ms |
24000 KB |
Output is correct |
50 |
Correct |
222 ms |
95752 KB |
Output is correct |
51 |
Correct |
138 ms |
41688 KB |
Output is correct |
52 |
Correct |
252 ms |
87060 KB |
Output is correct |
53 |
Correct |
222 ms |
80860 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
49 ms |
43980 KB |
Output is correct |
56 |
Correct |
148 ms |
56444 KB |
Output is correct |
57 |
Correct |
127 ms |
49320 KB |
Output is correct |
58 |
Correct |
169 ms |
78548 KB |
Output is correct |
59 |
Correct |
158 ms |
46044 KB |
Output is correct |
60 |
Correct |
464 ms |
116580 KB |
Output is correct |
61 |
Correct |
483 ms |
116608 KB |
Output is correct |
62 |
Correct |
501 ms |
116396 KB |
Output is correct |
63 |
Correct |
481 ms |
116872 KB |
Output is correct |
64 |
Correct |
512 ms |
116736 KB |
Output is correct |
65 |
Correct |
304 ms |
103416 KB |
Output is correct |
66 |
Correct |
294 ms |
103500 KB |
Output is correct |
67 |
Correct |
321 ms |
103424 KB |
Output is correct |
68 |
Correct |
207 ms |
60188 KB |
Output is correct |
69 |
Correct |
197 ms |
56564 KB |
Output is correct |
70 |
Correct |
236 ms |
72132 KB |
Output is correct |
71 |
Correct |
314 ms |
82204 KB |
Output is correct |