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. ural1987 Nested Segments

    Nested Segments Time limit: 1.0 secondMemory limit: 64 MB You are given n segments on a straight lin ...

  2. PL/SQL Developer使用技巧、快捷键、存储过程调试

    1.类SQL PLUS窗口:File->New->Command Window,这个类似于oracle的客户端工具sql plus,但比它好用多了. 2.设置关键字自动大写:Tools-& ...

  3. JQuery使用和选择器

    1.优点 (1)能解决浏览器的兼容性JS问题 (2)解决JS代码冗余的问题 (3)动画效果更容易实现 2.压缩过的和不压缩的区别 (1)开发过程中用未压缩的:上线后用压缩版本. (2)版本问题:1.X ...

  4. js MD5加密后的字符串

    js MD5加密后的字符串 <script language="JavaScript"> /************************************** ...

  5. SpringMVC轻松学习-其他常用(四)

    Spring MVC 3.0 深入 核心原理 1.      用户发送请求给服务器.url:user.do 2.      服务器收到请求.发现DispatchServlet可以处理.于是调用Disp ...

  6. hadoop hdfs uri详解

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  7. 使用for循环输出空心的菱形的思路-还是没有办法理解

    之前已经成功写过一次代码,今天重新看这个题目时,一下子又没了思路,在草稿纸上比划了大概十分钟才想到实现的思路.思路跟上次实现的完全一样,发现时间长了就忘记了!真是好记性不如烂笔头,何况我这么差的记性呢 ...

  8. Ubuntu和win10双系统Grup无法引导解决方案

    通常我们经常安装双系统, 但是有时候安装完系统无法正常引导, 以下就说明Ubuntu和win10双系统, win10在grub界面不断循环的解决方案 直接在win10启动项目上按e进入编辑模式 在文档 ...

  9. 从零开始HTML

      1.属性 HTML 标签可以拥有属性.属性提供了有关 HTML 元素的更多的信息.属性总是以名称/值对的形式出现,比如:name="value". 属性总是在 HTML 元素的 ...

  10. css3常用样式集锦

    控制线显示0.5px .line:after{ content:""; display:block; position:absolute; width:200%; left:0; ...