Codeforces Round #392 (Div. 2) 758C Unfair Poll 【Analog】

Topic Portal: Click to open the link

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 withm 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: the1-st row, the 2-nd row,..., the n - 1-st row, then-th row, the n - 1-st row,..., the 2-nd row, the1-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 thex-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 n,m, k,x 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;

The meaning of the question: There is a classroom: there are n rows and m columns. There is a student in each seat. The teacher has k questions to ask the classmates. The order of her questions is this (in terms of rows): 1, 2, 3.. . . . . n,n-1,n-2,n-3.......1

Each row starts at number 1 and ends at number m. Ask in this way. How many questions did the students who answered the most questions answered? How many questions did you answer at least? Xiaoming is in row x, column y. How many questions has Xiaoming answered?


We can draw several cycles in this order. It is not difficult to find that a cycle is: 1, 2, 3, 4,. . . . n,n-1,n-2,...,2 

in this cycle. Both the first row and the nth row were asked only once.

Following this rule, we use a two-dimensional array to simulate classroom seating. The value of each element represents the number of questions answered by students at that position. Just one last scan


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M(a)  memset(a,0,sizeof(a))
LL num[105][105];///Record the number of questions for each seat
intmain()
{
    LL k;
    LL n,m,x,y;
    while(~scanf("%lld %lld %lld %lld %lld",&n,&m,&k,&x,&y))
    {
        M(num);
        if(n==1)///When there is only one row, it is divided into a single case
        {
            LL temp=k%m;///temp represents the remainder outside the cycle
            LL temp2=(k-temp)/m;
            for(int i=1; i<=m; i++)
            {
                if(temp>0)
                {
                    temp--;
                    num[1][i]++;
                }
                num[1][i]+=temp2;
            }
            LL MIN=num[1][1];
            LL MAX=num[1][1];
            for(int i=1; i<=m; i++)///Get the maximum and minimum values
            {
                if(num[1][i]<=MIN)
                {
                    MIN = num [1] [i];
                }
                if(num[1][i]>=MAX)
                {
                    MAX=num[1][i];
                }

            }
            printf("%lld %lld %lld\n",MAX,MIN,num[x][y]);
        }
        else
        {
            LL temp=k%(2*n*m-2*m);
            LL temp2=(k-temp)/(2*n*m-2*m);
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    if(i==1||i==n)
                    {
                        num[i][j]=temp2;///The first line and the nth line are only answered once in a cycle
                    }
                    else
                    {
                        num[i][j]=temp2*2;///Other lines are twice
                    }
                }
            }

            while(temp>0)///The part outside the processing cycle
            {
                for(int i=1; i<=n&&temp>0; i++)
                {
                    if(i==n)
                    {
                        for(int c=n; c>=2&&temp>0; c--)
                        {
                            for(int l=1; l<=m&&temp>0; l++)
                            {

                                temp--;
                                num[c][l]++;
                            }

                        }
                    }
                    else
                    {
                        for(int j=1; j<=m&&temp>0; j++)
                        {
                            temp--;
                            num[i][j]++;
                        }
                    }
                }
            }

//            for(int i=1; i<=n; i++)
//            {
//                for(int j=1; j<=m; j++)
//                {
//                    printf("%d ",num[i][j]);
//                }
//                printf("\n");
//            }

            LL MAX=num[1][1];
            LL MIN=num[1][1];
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    if(num[i][j]<=MIN)
                    {
                        MIN = num [i] [j];
                    }
                    if(num[i][j]>=MAX)
                    {
                        MAX=num[i][j];
                    }
                }
            }
            printf("%lld %lld %lld\n",MAX,MIN,num[x][y]);


        }


    }
    return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325946486&siteId=291194637