#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,l,v[2003][2003],ans[2003],fix[2003];
vector<pair<pair<ll,ll> , ll> >g[2003];
__int128 a,b,c,d;
int main(){
ios::sync_with_stdio(false);
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];
}
ll cur = 1 , don = 0 , cnt = 0;
for(int j=1; j<=l; j++){
//cout << i << "<-->" << j << " " << cur << " " << cnt << '\n';
while((cnt + v[i][j]) * n >= cur * sum){
g[cur].pb(mp(mp((j - 1) * v[i][j] * n + (cur * sum - cnt * n) , v[i][j] * n) , i));
//cout << i << " " << cur << " " << (j - 1) * v[i][j] * n + (cur * sum - cnt * n) << " " << v[i][j] * n << '\n';
cur++;
}
cnt += v[i][j];
}
}
for(int i=1; i<n; i++){
ll mna = 100000000000000000 , mnb = 1 , ind = -1;
for(int j=0; j<g[i].size(); j++){
if(fix[g[i][j].s])continue;
a = mna;
b = mnb;
c = g[i][j].f.f;
d = g[i][j].f.s;
a *= d;
c *= b;
if(a > c){
mna = g[i][j].f.f;
mnb = g[i][j].f.s;
ind = g[i][j].s;
}
}
ans[i] = ind;
fix[ind] = 1;
cout << mna << " " << mnb << '\n';
}
for(int i=1; i<=n; i++)
if(!fix[i])ans[n] = i;
for(int i=1; i<=n; i++)
cout << ans[i] << " ";
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:21:22: warning: unused variable 'don' [-Wunused-variable]
ll cur = 1 , don = 0 , cnt = 0;
^~~
naan.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<g[i].size(); j++){
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
6 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
508 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
6 ms |
504 KB |
Output is correct |
15 |
Correct |
5 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 |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
6 ms |
504 KB |
Output is correct |
22 |
Correct |
6 ms |
504 KB |
Output is correct |
23 |
Correct |
5 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 |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
508 KB |
Output is correct |
20 |
Correct |
5 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
504 KB |
Output is correct |
24 |
Correct |
6 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
508 KB |
Output is correct |
26 |
Correct |
5 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
5 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 |
6 ms |
504 KB |
Output is correct |
34 |
Correct |
6 ms |
504 KB |
Output is correct |
35 |
Correct |
6 ms |
504 KB |
Output is correct |
36 |
Correct |
6 ms |
504 KB |
Output is correct |
37 |
Correct |
6 ms |
504 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
6 ms |
504 KB |
Output is correct |
40 |
Correct |
5 ms |
504 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
504 KB |
Output is correct |
43 |
Correct |
49 ms |
17912 KB |
Output is correct |
44 |
Correct |
283 ms |
87032 KB |
Output is correct |
45 |
Correct |
172 ms |
34168 KB |
Output is correct |
46 |
Correct |
28 ms |
3832 KB |
Output is correct |
47 |
Correct |
206 ms |
47352 KB |
Output is correct |
48 |
Correct |
195 ms |
106876 KB |
Output is correct |
49 |
Correct |
67 ms |
29944 KB |
Output is correct |
50 |
Correct |
327 ms |
129016 KB |
Output is correct |
51 |
Correct |
178 ms |
60664 KB |
Output is correct |
52 |
Correct |
342 ms |
113580 KB |
Output is correct |
53 |
Correct |
270 ms |
107128 KB |
Output is correct |
54 |
Correct |
6 ms |
504 KB |
Output is correct |
55 |
Correct |
91 ms |
67612 KB |
Output is correct |
56 |
Correct |
217 ms |
78716 KB |
Output is correct |
57 |
Correct |
186 ms |
70520 KB |
Output is correct |
58 |
Correct |
235 ms |
105172 KB |
Output is correct |
59 |
Correct |
195 ms |
66168 KB |
Output is correct |
60 |
Correct |
599 ms |
150200 KB |
Output is correct |
61 |
Correct |
631 ms |
150368 KB |
Output is correct |
62 |
Correct |
621 ms |
149820 KB |
Output is correct |
63 |
Correct |
599 ms |
150360 KB |
Output is correct |
64 |
Correct |
598 ms |
150284 KB |
Output is correct |
65 |
Correct |
439 ms |
136984 KB |
Output is correct |
66 |
Correct |
441 ms |
137080 KB |
Output is correct |
67 |
Correct |
445 ms |
136944 KB |
Output is correct |
68 |
Correct |
224 ms |
83552 KB |
Output is correct |
69 |
Correct |
257 ms |
78072 KB |
Output is correct |
70 |
Correct |
254 ms |
97572 KB |
Output is correct |
71 |
Correct |
384 ms |
107640 KB |
Output is correct |