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:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. 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 nmkx and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. 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:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;

数学题, 做法很丑。

 //2017.01.20
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int n, m, x, y;
long long k;
long long maximum, minimum, cnt;
while(cin>>n>>m>>k>>x>>y)
{
if(n==){
if(k%m==)maximum = minimum = k/m;
else{
maximum = k/m+;
minimum = maximum-;
}
}else{
long long row = k/m;
if(row*m != k)row++;
if(n==)maximum = (row+)/n;
else maximum = (row-)/(n-)+;
minimum = (row+n-)/(*n-);
if(minimum*(*n-) == (row+n-) && row*m != k)
minimum--;
}
int pos = (x-)*m+y;
if(n==)
{
if(pos <= k%m)cnt = maximum;
else cnt = minimum;
}else
{
long long cyc = k/(m*(*n-));
cnt = (x==||x==n) ? cyc : *cyc;
long long other = k-cyc*(m*(*n-));
if(other < pos)cnt+=;
else if(((n--x)*m+y)>(other-m*n)||(x==||x==n))cnt+=;
else cnt+=;
} cout<<maximum<<" "<<minimum<<" "<<cnt<<endl; } return ;
}

Codeforces758C的更多相关文章

  1. Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. [算法] avl树实现

    大二的时候数据结构课死活没看懂的一个东东,看了2小时,敲了2小时,调了2小时... 平衡树某一节点的左右子树高度相差大于1的时候即需要调整,调整可分为四中情况 ll,rr,lr,rl其中lr,rl是由 ...

  2. nginx 防 webshell 跨目录

    对于在一台服务器上有多个虚拟主机的人来说,Apache有一个很好用的地方---配置php_admin_value,在里面配置一下 open_basedir就可以了.   但是Nginx却没有这样的设置 ...

  3. selenium 多线程

    http://www.cnblogs.com/dingmy/p/3438084.html

  4. (中等) POJ 1703 Find them, Catch them,带权并查集。

    Description The police office in Tadu City decides to say ends to the chaos, as launch actions to ro ...

  5. stm32-ucos移植lwip-1(raw)

    之前在裸机环境下移植了lwip,功能还是很强大的,但是就我看来,这和uip其实差别也不大,其实lwip更强大的功能需要在操作系统之下才能发挥出来,今天就来做这个 首先我们需要移植操作系统,系统选择uc ...

  6. ZOJ 3931 Exact Compression

    题目看了半小时才看懂的. 题意:首先根据给出的序列,构造出哈夫曼树,构造出来的是一棵二叉树,每个节点都有一个权值,每个节点的两个儿子只能取一个,问能否使取出来的节点权值之和刚好等于e. 这样一分析就很 ...

  7. 入门经典——基础数据结构专题(List)

    UVA127 链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. uartz Spring与Spring Task总结

    Spring对Quartz作了一个封装,同时,Spring自己也提供了一个任务定时器(spring-task),现把它总结一下.    对于Quartz,我们使用的时候主要是注重两个方面,一个是定时任 ...

  9. EF LINQ根据某个字段去除重复行

    1.ydc.GameScore.OrderByDescending(o => o.Score).GroupBy(ic => ic.UserPhone).Select(g => g.F ...

  10. iOS开发——工厂模式

    工厂模式很好用,为表诚意,我直接搞个实用的例子放这,解析一个订单的数据,并且这个订单里面可能不止一件商品的做法. 还是直接上代码,不懂的地方,再提出来. 1.在MyOrderDeals.h文件中 #i ...