time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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;

【题目链接】:http://codeforces.com/contest/758/problem/C

【题解】



画一画;

会发现;

走完第一行之后;

之后每2*(n-1)*m个格子为一个周期;

这一个周期;

固定把第一行和最后一行的格子每个格子递增1;

同时第二行到第n-1行每个格子都递增2;

我是以k<=n*m和k>n*m作为划分的;

对于k<=n*m的情况直接暴力模拟(n*m最大为10000完全可以接受);

对于k>n*m的情况

先把第一行都加上1(先走完第一行);

然后k-=m;

周期的个数就为k/(2*(n-1)*m);

然后对于剩下的k%(2*(n-1)*m)

暴力搞完就好;

特判一下n=1的情就好;

不会很难的;

到了n+1则变成n-1,转个方向;

到了0则变成2,转个方向;



【完整代码】

#include <bits/stdc++.h>
#define LL long long using namespace std; int x,y;
LL n,m,k;
LL a[110][110]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> m >> k >> x >> y;
if (k<=n*m)
{
int rest = k;
int nx = 1,ny = 1,fx=1;
while (rest>0)
{
a[nx][ny]++;
rest--;
ny++;
if (ny>m)
{
ny = 1;
nx+=fx;
}
if (nx>n)
{
nx-=2;
fx=-fx;
}
if (nx<1)
{
nx = 2;
if (nx>n)
nx = 1;
fx=-fx;
}
}
}
else
if (k > n*m)
{
if (n>1)
{
for (int i = 1;i <= m;i++)
a[1][i] = 1;
LL temp,rest;
k-=m;
temp = k/(2*(n-1)*m);
rest = k%(2*(n-1)*m);
for (int i = 1;i <= m;i++)
a[1][i]+=temp,a[n][i]+=temp;
for (int i = 2;i <= n-1;i++)
for (int j = 1;j <= m;j++)
a[i][j]+=temp*2;
int nx = 2,ny = 1,fx=1;
if (nx>n)
nx = 1;
while (rest>0)
{
a[nx][ny]++;
rest--;
ny++;
if (ny>m)
{
ny = 1;
nx+=fx;
}
if (nx>n)
{
nx-=2;
fx=-fx;
}
if (nx<1)
{
nx = 2;
fx = -fx;
}
}
}
else
if (n==1)
{
LL temp = k/m;
LL rest = k%m;
for (int i = 1;i <= m;i++)
a[1][i]+=temp;
for (int i = 1;i <= rest;i++)
a[1][i]++;
}
}
LL ma = a[1][1],mi = a[1][1];
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
{
ma = max(ma,a[i][j]);
mi = min(mi,a[i][j]);
}
cout << ma << ' ' <<mi << ' '<<a[x][y]<<endl;
return 0;
}

【codeforces 758C】Unfair Poll的更多相关文章

  1. Codeforces 758C:Unfair Poll(思维+模拟)

    http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. Scala——构造函数

    Scala的构造函数分为主构造函数和辅助构造函数. 辅助构造函数 辅助构造函数比较容易理解,它们同C++和Java的构造函数十分类似,只有两处不同: 1.辅助构造函数的名称为this,这主要是考虑到在 ...

  2. CISP/CISA 每日一题

    CISA 业务流程控制鉴证中要考虑的特定因素: 1.流程图 2.流程控制 3.在流程中评估业务风险 4.对最佳实践进行标杆管理 5.角色与责任 6.活动与任务 7.数据限制   信息系统审计师的任务是 ...

  3. 洛谷 P1893 山峰暸望

    P1893 山峰暸望 题目描述 一天,Bessie在眺望美丽的威斯康星的群山的时候,她突然产生了疑问:那座山是最宽的? 她决定在地平线上,利用她的新式大量程山峰高度测量仪依次做N (1 <= N ...

  4. 在C#中实现Word页眉页脚的全部功能

    页眉页脚经常使用于文章排版,在Word工具栏里.我们能够加入页眉,页脚,页码,日期和时间.图片等信息和内容.页眉/页脚有两个额外选项:首页不同,奇偶页不同.有时在不同的节(section)里插入不同的 ...

  5. 含有打印、统计DataGridView(1)

    using System;using System.Collections.Generic;using System.Text;using System.Drawing.Printing;using ...

  6. python缩进报错

    1.这个错误应该已经好久了:也应该熟悉了才对 IndentationError: unexpected indent python 缩进错误:意外缩进Python 但今天的问题有点特殊,我想在程序中间 ...

  7. js数组遍历和对象遍历小结

    数组的遍历 for循环 for(var j = 0,len = arr.length; j < len; j++){ console.log(arr[j]); } forEach,性能比for还 ...

  8. Python 极简教程(十三)while 循环

    循环简单来说就是让一段代码按你想要的方式多次运行.软件拥有强大的运算能力,就是由循环提供的. 在 Python 中支持的循环由两种:while 循环 和for 循环. 现在我们先来讲while循环. ...

  9. c# 调用 C++ dll 传入传出 字符串

    c# 调用 C++ dll 传入传出 字符串 2013-07-02 09:30 7898人阅读 评论(2) 收藏 举报 本文章已收录于:   分类: windows 版权声明:随便转载,随便使用. C ...

  10. Mycat常见问题与解决方案---宜将剩勇追穷寇,不可沽名学霸王

    1 Mycat目前有哪些功能与特性? 答: • 支持 SQL 92标准 • 支持Mysql集群,可以作为Proxy使用 • 支持JDBC连接多数据库 • 支持NoSQL数据库 • 支持galera f ...