This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 2000
#define M 2000
int main() {
static int ww[N][M + 1], pp[N][N + 1], qq[N][N + 1], ii[N];
int n, m, g, g_, g1, i, j, d, tmp;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
for (j = 1; j <= m; j++) {
scanf("%d", &ww[i][j]);
ww[i][j] += ww[i][j - 1];
}
for (i = 0; i < n; i++) {
pp[0][0] = 0, qq[0][0] = 1, pp[0][n] = m, qq[0][n] = 1;
for (g = 1, j = 0; g < n; g++) {
while (j < m && (long long) ww[i][j + 1] * n < (long long) ww[i][m] * g)
j++;
d = ww[i][j + 1] - ww[i][j];
pp[i][g] = (long long) j * n * d + (long long) ww[i][m] * g - (long long) ww[i][j] * n, qq[i][g] = n * d;
}
}
for (i = 0; i < n; i++)
ii[i] = i;
for (g = 0; g + 1 < n; g++) {
g1 = g;
for (g_ = g + 1; g_ < n; g_++)
if ((long long) pp[ii[g1]][g + 1] * qq[ii[g_]][g + 1] > (long long) pp[ii[g_]][g + 1] * qq[ii[g1]][g + 1])
g1 = g_;
tmp = ii[g], ii[g] = ii[g1], ii[g1] = tmp;
}
for (g = 0; g + 1 < n; g++)
printf("%d %d\n", pp[ii[g]][g + 1], qq[ii[g]][g + 1]);
for (g = 0; g < n; g++)
printf("%d ", ii[g] + 1);
printf("\n");
return 0;
}
Compilation message (stderr)
naan.c: In function 'main':
naan.c:10:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
naan.c:13:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", &ww[i][j]);
| ^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |