您的位置:首页 > 大数据 > 人工智能

Codeforces758C Unfair Poll

2017-01-20 10:24 92 查看
C. Unfair Poll

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils
in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it
means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd
row, ..., the n - 1-st
row, the n-th row, the n - 1-st
row, ..., the 2-nd row,
the 1-st row, the 2-nd
row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd
pupil, ..., the m-th
pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th
row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three
values:

the maximum number of questions a particular pupil is asked,

the minimum number of questions a particular pupil is asked,

how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.

Input

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

the maximum number of questions a particular pupil is asked,

the minimum number of questions a particular pupil is asked,

how many times the teacher asked Sergei.

Examples

input
1 3 8 1 1


output
3 2 3


input
4 2 9 4 2


output
2 1 1


input
5 5 25 4 3


output
1 1 1


input
100 100 1000000000000000000 100 100


output
101010101010101 50505050505051 50505050505051


Note

The order of asking pupils in the first test:

the pupil from the first row who seats at the first table, it means it is Sergei;

the pupil from the first row who seats at the second table;

the pupil from the first row who seats at the third table;

the pupil from the first row who seats at the first table, it means it is Sergei;

the pupil from the first row who seats at the second table;

the pupil from the first row who seats at the third table;

the pupil from the first row who seats at the first table, it means it is Sergei;

the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

the pupil from the first row who seats at the first table;

the pupil from the first row who seats at the second table;

the pupil from the second row who seats at the first table;

the pupil from the second row who seats at the second table;

the pupil from the third row who seats at the first table;

the pupil from the third row who seats at the second table;

the pupil from the fourth row who seats at the first table;

the pupil from the fourth row who seats at the second table, it means it is Sergei;

the pupil from the third row who seats at the first table;

——————————————————————————————————————
题意:老师点名字按顺序点,排与排之间按1,2……n-1,n,n-1……2,1,2这样,每排按顺序点,输入n排m列,点k次,主人公位置(x,y),问最多的人点几次,最少的人点几次,主人公点几次?

思路:博主用了最笨的方法 分类讨论,特判n=1和n=2;可惜考虑不到位终测挂了,气

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>

using namespace std;

int main()
{
long long m,n,k,x,y;
while(~scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y))
{
if(k==m&&n==1)
{
printf("1 1 1\n");
continue;
}
if(k<=m)
{
if(x==1&&y<=k)
printf("1 0 1\n");
else
printf("1 0 0\n");
continue;
}

if(n==1)
{
long long  ttt=k/m;
long long tt=k%m;
if(y<=tt)
{
if(tt==0)
printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
else
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt+1);
}
else
{
if(tt==0)
printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
else
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt);
}
continue;
}
if(n==2)
{
long long  ttt=k/(m*2);
long long tt=k%(m*2);
long long ttc=(x-1)*m+y;
if(tt==0)
printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
else
{
if(tt<ttc)
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt);
else
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt+1);
}
continue;
}
k-=m;
long long int cnt=k/(m*(n-1));
long long  int md=k%(m*(n-1));
long long  int zheng=(x-1)*m+y-m;
long long int fan=(n-x)*m+y-m;
if(cnt%2==1)
{
if(x==1)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt/2+1);
else
{
if(fan>md)
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+1);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+2);

}

}
else if(x==n)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt/2+1);
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+1);
}
}
else if(fan>md)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt);
}
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt+1);
}
}
else
{
if(x==1)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt/2+1);
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2+1);
}

}
else if(x==n)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt/2);
else
{
if(zheng>md)
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2+1);
}
}
else if(zheng>md)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt);
}
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt+1);
}
}

}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: