【Codeforces 758 C Unfair Poll】+ 细节

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….的排顺序提问,每排按1~M的顺序提问,问题问次数最多的同学次数,最少的同学次数,以及Sergei的提问次数:

思路 :
1 )N 为1或2时单独处理;
2 ) N大于2时,循环周期为 2 ×(N - 1)× M,最多的为中间的,最少的为第一排的或最后一排的,Sergei的单独判断,当Sergei为第一排或最后一排时需特断;

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    LL N,M,K,X,Y,ma,na,aa,nl,ml;
    scanf("%lld %lld %lld %lld %lld",&N,&M,&K,&X,&Y);
    if(N > 2){
    nl = K / (2 * (N - 1) * M),ma = nl * 2,ml = K % (2 * (N - 1) * M);
    if(ml > M) ma++;
    if(ml > N * M) ma++;
    if(ma == 0 && K != 0) ma = 1;
    LL m1 = nl,m2 = nl;
    if(ml >= M) m1++;
    if(ml >= N * M) m2++;
    na = min(m1,m2);
    aa = nl * 2;
    if(ml >= (X - 1) * M + Y) aa++;
    if(ml >= (N * 2 - 1 - X) * M + Y) aa++;
    if(X == 1){
        aa = m1;
        if(ml < M && ml >= Y)
            aa++;
    }
    if(X == N){
        aa = m2;
        if(ml < N * M && ml >= (X - 1) * M + Y)
            aa++;
    }
    }
    else{
        nl = K / (N * M),ml = K % (N * M),ma = nl,na = nl,aa = nl;
        if(ml) ma++;
        if(ml >= (X - 1)* M + Y) aa++;
    }
    printf("%lld %lld %lld\n",ma,na,aa);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值