Submission #856320

#TimeUsernameProblemLanguageResultExecution timeMemory
856320JooDdaeNaan (JOI19_naan)C++17
29 / 100
104 ms25556 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; bool operator < (const array<ll, 2> a, const array<ll, 2> b) { return a[0]*b[1] < b[0]*a[1]; } int n, m, c[2020][2020]; bool chk[2020]; array<ll, 2> p[2020][2020]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >> c[i][j]; for(int i=1;i<=n;i++) { ll sum = 0; for(int j=1;j<=m;j++) sum += c[i][j]; ll s = 0; for(int j=1, k=0;j<n;j++) { while(k < m && (s + c[i][k+1]) * n <= sum * j) s += c[i][++k]; ll C = c[i][k+1]; p[i][j] = {sum*j-s*n + k*C*n, C*n}; assert(j == 1 || p[i][j-1] < p[i][j]); } } vector<int> ans; for(int i=1;i<n;i++) { int mn = 1; while(chk[mn]) mn++; for(int j=1;j<=n;j++) if(!chk[j] && p[j][i] < p[mn][i]) mn = j; assert(1 <= p[mn][i][1] && p[mn][i][1] <= (int)1e9); cout << p[mn][i][0] << " " << p[mn][i][1] << "\n"; chk[mn] = 1, ans.push_back(mn); } for(auto x : ans) cout << x << " "; for(int i=1;i<=n;i++) if(!chk[i]) cout << i; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...