Codeforces Round #392 (Div. 2), problem: (C) Unfair Poll Solution in C/C++

#include <stdio.h>

int n,m,X,Y;
long long K;

long long ans[110][110];

int main()
{
int i,j,t;
long long mn = 1e18, mx = 0;

scanf(“%d%d%I64d%d%d”,&n,&m,&K,&X,&Y);
t = (n > 1 ? (2*n-2)*m : m);
for(i=2;i<n;i++) for(j=1;j<=m;j++) ans[i][j] = K/t*2;
for(j=1;j<=m;j++) ans[1][j] = ans[n][j] = K/t;
K %= t;

for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(K > 0)
ans[i][j]++, K–;
for(i=n-1;i>1;i–) for(j=1;j<=m;j++) if(K > 0)
ans[i][j]++, K–;

for(i=1;i<=n;i++) for(j=1;j<=m;j++)
{
mn = (mn < ans[i][j] ? mn : ans[i][j]);
mx = (mx > ans[i][j] ? mx : ans[i][j]);
}
printf(“%I64d %I64d %I64d”,mx,mn,ans[X][Y]);
return 0;
}

(Visited 137 times, 1 visits today)

About the Author:

Leave A Comment