#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define pii pair<int,int>
const int INF=1e18;
bool operator<(pair<int,int> a,pair<int,int> b){
return a.first*b.second<a.second*b.first;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
long long n1,m1;cin>>n1>>m1;
n=n1,m=m1;
vector<int> a(n);
vector<vector<int>> v(n,vector<int>(m)),pre(n,vector<int>(m));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
long long tmp=0;cin>>tmp;
v[i][j]=tmp;
v[i][j]*=n;
a[i]+=v[i][j];
}
a[i]/=n;
}
/*for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<v[i][j]<<' ';
}
cout<<endl;
}*/
for(int i=0;i<n;i++){
pre[i][0]=v[i][0];
for(int j=1;j<m;j++){
pre[i][j]=pre[i][j-1]+v[i][j];
}
}
vector<bool> vis(n);
vector<vector<pair<int,int>>> rec(n,vector<pair<int,int>>(n));
for(int i=0;i<n;i++){
int need=0;
int ptr=0;
for(int j=0;j<n-1;j++){
need+=a[i];
while(ptr<m&&pre[i][ptr]<need){
ptr++;
}
int p=(ptr>0?pre[i][ptr-1]:0);
rec[i][j]={need-p+ptr*v[i][ptr],v[i][ptr]};
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<"("<<rec[i][j].first<<","<<rec[i][j].second<<") ";
}
cout<<endl;
}*/
vector<int> ans(n);
for(int i=0;i<n-1;i++){
int idx=-1;
for(int j=0;j<n;j++){
if(vis[j]){
continue;
}
if(idx==-1){
idx=j;
}
else if(rec[j][i]<rec[idx][i]){
idx=j;
}
}
ans[i]=idx+1;
vis[idx]=1;
cout<<(long long)rec[idx][i].first<<' '<<(long long)rec[idx][i].second<<endl;
}
for(int i=0;i<n;i++){
if(vis[i]==0){
ans[n-1]=i+1;
}
}
for(int j=0;j<n;j++){
cout<<(long long)ans[j]<<' ';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 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 |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
240 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 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 |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
596 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 |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
724 KB |
Output is correct |
37 |
Correct |
1 ms |
724 KB |
Output is correct |
38 |
Correct |
1 ms |
240 KB |
Output is correct |
39 |
Correct |
1 ms |
596 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
596 KB |
Output is correct |
43 |
Correct |
33 ms |
18456 KB |
Output is correct |
44 |
Correct |
196 ms |
112716 KB |
Output is correct |
45 |
Correct |
130 ms |
62972 KB |
Output is correct |
46 |
Correct |
18 ms |
8024 KB |
Output is correct |
47 |
Correct |
160 ms |
82996 KB |
Output is correct |
48 |
Correct |
155 ms |
139252 KB |
Output is correct |
49 |
Correct |
53 ms |
40888 KB |
Output is correct |
50 |
Correct |
280 ms |
207696 KB |
Output is correct |
51 |
Correct |
180 ms |
92008 KB |
Output is correct |
52 |
Correct |
309 ms |
201460 KB |
Output is correct |
53 |
Correct |
226 ms |
165212 KB |
Output is correct |
54 |
Correct |
1 ms |
596 KB |
Output is correct |
55 |
Correct |
72 ms |
67312 KB |
Output is correct |
56 |
Correct |
184 ms |
125696 KB |
Output is correct |
57 |
Correct |
139 ms |
102072 KB |
Output is correct |
58 |
Correct |
220 ms |
156936 KB |
Output is correct |
59 |
Correct |
182 ms |
109932 KB |
Output is correct |
60 |
Correct |
478 ms |
262144 KB |
Output is correct |
61 |
Correct |
496 ms |
262144 KB |
Output is correct |
62 |
Correct |
474 ms |
262144 KB |
Output is correct |
63 |
Correct |
466 ms |
262144 KB |
Output is correct |
64 |
Correct |
447 ms |
262144 KB |
Output is correct |
65 |
Correct |
356 ms |
259596 KB |
Output is correct |
66 |
Correct |
370 ms |
259780 KB |
Output is correct |
67 |
Correct |
363 ms |
259804 KB |
Output is correct |
68 |
Correct |
169 ms |
117780 KB |
Output is correct |
69 |
Correct |
196 ms |
123844 KB |
Output is correct |
70 |
Correct |
195 ms |
140364 KB |
Output is correct |
71 |
Correct |
283 ms |
186628 KB |
Output is correct |