Submission #153006

#TimeUsernameProblemLanguageResultExecution timeMemory
153006oolimryNaan (JOI19_naan)C++14
100 / 100
2141 ms85320 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> ii; bool great(ii a, ii b){ long long wa = a.first / a.second; long long wb = b.first / b.second; if(wa == wb){ a.first %= a.second, b.first %= b.second; return a.first * b.second < a.second * b.first; } return wa < wb; //is b greater than a } int main(){ //freopen("i.txt","r",stdin); cin.tie(0); long long n, l; cin >> n >> l; long long arr[n][l]; long long sums[n]; fill(sums,sums+n,0); for(long long i = 0;i < n;i++) for(long long j = 0;j < l;j++){ cin >> arr[i][j]; sums[i] += arr[i][j]; arr[i][j] *= n; } long long pre[n][l]; for(long long i = 0;i < n;i++) for(long long j = 0;j < l;j++){ pre[i][j] = arr[i][j]; if(j != 0) pre[i][j] += pre[i][j-1]; } bool used[n]; fill(used,used+n,false); vector<long long> order; for(long long r = 0;r < n;r++){ ii minfrac = ii(102344213,1); long long mini; for(long long i = 0;i < n;i++){ if(used[i]) continue; long long need = (r+1) * sums[i]; long long x = upper_bound(pre[i],pre[i]+l,need) - pre[i]; ii frac; frac.second = arr[i][x]; frac.first = need; if(x != 0) frac.first -= pre[i][x-1]; frac.first += x * frac.second; if(great(frac,minfrac)){ minfrac = frac; mini = i; } } if(r != n-1) cout << minfrac.first << " " << minfrac.second << "\n"; used[mini] = true; order.push_back(mini); } for(int i = 0;i < n;i++){ cout << order[i] + 1 << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...