#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 4e18;
struct Frac{
ll a, b;
Frac(){}
Frac(ll _a, ll _b): a(_a), b(_b) {}
bool operator < (const Frac &F) const{
return (__int128)a*F.b < (__int128)b*F.a;
}
};
int n, m, used[2020];
ll a[2020];
vector<Frac> V[2020];
void input(int i){
ll S = 0;
for (int j=1;j<=m;j++){
cin >> a[j];
S += a[j];
}
ll cur = S, c = 1, pt = 1;
while(c<n){
if (a[pt]*n < cur) {cur -= a[pt++]*n; continue;}
V[c].emplace_back(cur + a[pt]*n*(pt-1), a[pt]*n);
cur += S;
c++;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=1;i<=n;i++) input(i);
vector<int> ans;
for (int i=1;i<=n-1;i++){
Frac mn(INF, 1);
int idx = -1;
for (int j=1;j<=n;j++) if (!used[j] && V[i][j-1] < mn){
mn = V[i][j-1];
idx = j;
}
ans.push_back(idx);
used[idx] = 1;
cout << mn.a << ' ' << mn.b << '\n';
}
for (int j=1;j<=n;j++) if (!used[j]) ans.push_back(j);
for (auto &x:ans) cout << x << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
372 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 |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
396 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
380 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
388 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
372 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 |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
396 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
400 KB |
Output is correct |
16 |
Correct |
1 ms |
380 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
388 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
30 ms |
10028 KB |
Output is correct |
44 |
Correct |
191 ms |
49812 KB |
Output is correct |
45 |
Correct |
110 ms |
18548 KB |
Output is correct |
46 |
Correct |
18 ms |
1788 KB |
Output is correct |
47 |
Correct |
128 ms |
24316 KB |
Output is correct |
48 |
Correct |
114 ms |
62572 KB |
Output is correct |
49 |
Correct |
41 ms |
15408 KB |
Output is correct |
50 |
Correct |
219 ms |
69320 KB |
Output is correct |
51 |
Correct |
121 ms |
31440 KB |
Output is correct |
52 |
Correct |
227 ms |
61560 KB |
Output is correct |
53 |
Correct |
191 ms |
57932 KB |
Output is correct |
54 |
Correct |
1 ms |
384 KB |
Output is correct |
55 |
Correct |
46 ms |
41636 KB |
Output is correct |
56 |
Correct |
138 ms |
41312 KB |
Output is correct |
57 |
Correct |
106 ms |
37252 KB |
Output is correct |
58 |
Correct |
152 ms |
57956 KB |
Output is correct |
59 |
Correct |
129 ms |
34512 KB |
Output is correct |
60 |
Correct |
409 ms |
86596 KB |
Output is correct |
61 |
Correct |
385 ms |
86564 KB |
Output is correct |
62 |
Correct |
351 ms |
86348 KB |
Output is correct |
63 |
Correct |
357 ms |
86808 KB |
Output is correct |
64 |
Correct |
376 ms |
86596 KB |
Output is correct |
65 |
Correct |
303 ms |
73300 KB |
Output is correct |
66 |
Correct |
323 ms |
73500 KB |
Output is correct |
67 |
Correct |
299 ms |
73292 KB |
Output is correct |
68 |
Correct |
144 ms |
46256 KB |
Output is correct |
69 |
Correct |
170 ms |
42724 KB |
Output is correct |
70 |
Correct |
178 ms |
54740 KB |
Output is correct |
71 |
Correct |
226 ms |
60012 KB |
Output is correct |