#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,l;
ll v[2048][2048];
pair<ll,ll> p[2048][2048];
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2)
{
return p1.first*p2.second<p1.second*p2.first;
}
bool used[2048];
int main()
{
cin>>n>>l;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=l;j++)
{
cin>>v[i][j];
}
}
for(int i=1;i<=n;i++)
{
ll sum=0;
for(ll j=1;j<=l;j++)
{
sum+=v[i][j];
}
ll sumv=0,needed;
ll r=1;
for(ll j=1;j<n;j++)
{
needed=sum*j;
while(sumv+v[i][r]*n<=needed)
{
sumv+=v[i][r]*n;
r++;
}
p[i][j]={(r-1)*v[i][r]*n+needed-sumv,n*v[i][r]};
}
}
vector<int>ans;
for(int i=1;i<n;i++)
{
bool found=0;
pair<ll,ll> best;
ll idx;
for(int j=1;j<=n;j++)
{
if(used[j])continue;
if(!found||cmp(p[i][j],best))
{
best=p[i][j];found=1;
idx=j;
}
}
cout<<p[i][idx].first<<" "<<p[i][idx].second<<endl;
used[idx]=1;
ans.push_back(idx);
}
for(int i=1;i<=n;i++)if(!used[i])ans.push_back(i);
for(auto xd:ans)
{
cout<<xd<<" ";
}
cout<<endl;
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:59:16: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
59 | ans.push_back(idx);
| ~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Not a fair distribution. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
624 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
3 ms |
492 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
492 KB |
Output is correct |
19 |
Correct |
4 ms |
508 KB |
Output is correct |
20 |
Correct |
3 ms |
492 KB |
Output is correct |
21 |
Correct |
3 ms |
492 KB |
Output is correct |
22 |
Correct |
3 ms |
492 KB |
Output is correct |
23 |
Incorrect |
1 ms |
364 KB |
Not a fair distribution. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Not a fair distribution. |
2 |
Halted |
0 ms |
0 KB |
- |