#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ii;
bool great(ii a, ii b){
long long wa = a.first / a.second;
long long wb = b.first / b.second;
if(wa == wb){
a.first %= a.second, b.first %= b.second;
return a.first * b.second < a.second * b.first;
}
return wa < wb; //is b greater than a
}
int main(){
//freopen("i.txt","r",stdin);
cin.tie(0);
long long n, l;
cin >> n >> l;
long long arr[n][l];
long long sums[n];
fill(sums,sums+n,0);
for(long long i = 0;i < n;i++)
for(long long j = 0;j < l;j++){
cin >> arr[i][j];
sums[i] += arr[i][j];
arr[i][j] *= n;
}
long long pre[n][l];
for(long long i = 0;i < n;i++)
for(long long j = 0;j < l;j++){
pre[i][j] = arr[i][j];
if(j != 0) pre[i][j] += pre[i][j-1];
}
bool used[n];
fill(used,used+n,false);
vector<long long> order;
for(long long r = 0;r < n;r++){
ii minfrac = ii(102344213,1);
long long mini;
for(long long i = 0;i < n;i++){
if(used[i]) continue;
long long need = (r+1) * sums[i];
long long x = upper_bound(pre[i],pre[i]+l,need) - pre[i];
ii frac;
frac.second = arr[i][x];
frac.first = need;
if(x != 0) frac.first -= pre[i][x-1];
frac.first += x * frac.second;
if(great(frac,minfrac)){
minfrac = frac;
mini = i;
}
}
if(r != n-1) cout << minfrac.first << " " << minfrac.second << "\n";
used[mini] = true;
order.push_back(mini);
}
for(int i = 0;i < n;i++){
cout << order[i] + 1 << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
380 KB |
Output is correct |
4 |
Correct |
8 ms |
352 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
252 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
308 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
508 KB |
Output is correct |
15 |
Correct |
4 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
4 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
380 KB |
Output is correct |
4 |
Correct |
8 ms |
352 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
252 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
308 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
380 KB |
Output is correct |
19 |
Correct |
5 ms |
504 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
4 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
508 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
5 ms |
504 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
5 ms |
504 KB |
Output is correct |
36 |
Correct |
5 ms |
504 KB |
Output is correct |
37 |
Correct |
5 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
4 ms |
376 KB |
Output is correct |
40 |
Correct |
4 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
4 ms |
376 KB |
Output is correct |
43 |
Correct |
141 ms |
4392 KB |
Output is correct |
44 |
Correct |
962 ms |
27292 KB |
Output is correct |
45 |
Correct |
644 ms |
20596 KB |
Output is correct |
46 |
Correct |
95 ms |
3548 KB |
Output is correct |
47 |
Correct |
734 ms |
22452 KB |
Output is correct |
48 |
Correct |
473 ms |
13832 KB |
Output is correct |
49 |
Correct |
179 ms |
9464 KB |
Output is correct |
50 |
Correct |
953 ms |
45920 KB |
Output is correct |
51 |
Correct |
515 ms |
31160 KB |
Output is correct |
52 |
Correct |
1086 ms |
58428 KB |
Output is correct |
53 |
Correct |
803 ms |
40860 KB |
Output is correct |
54 |
Correct |
4 ms |
376 KB |
Output is correct |
55 |
Correct |
102 ms |
3064 KB |
Output is correct |
56 |
Correct |
640 ms |
38896 KB |
Output is correct |
57 |
Correct |
480 ms |
30172 KB |
Output is correct |
58 |
Correct |
634 ms |
35192 KB |
Output is correct |
59 |
Correct |
594 ms |
37780 KB |
Output is correct |
60 |
Correct |
2141 ms |
84780 KB |
Output is correct |
61 |
Correct |
2044 ms |
84864 KB |
Output is correct |
62 |
Correct |
2124 ms |
84556 KB |
Output is correct |
63 |
Correct |
2118 ms |
85320 KB |
Output is correct |
64 |
Correct |
2106 ms |
85016 KB |
Output is correct |
65 |
Correct |
1187 ms |
71732 KB |
Output is correct |
66 |
Correct |
1207 ms |
71812 KB |
Output is correct |
67 |
Correct |
1241 ms |
71724 KB |
Output is correct |
68 |
Correct |
639 ms |
32152 KB |
Output is correct |
69 |
Correct |
802 ms |
41976 KB |
Output is correct |
70 |
Correct |
715 ms |
34896 KB |
Output is correct |
71 |
Correct |
1166 ms |
59416 KB |
Output is correct |