Educational Codeforces Round 24

 

A. Diplomas and Certificates

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n students who have taken part in an olympiad. Now it's time to award the students.

Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.

You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

Input

The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

Output

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.

It's possible that there are no winners.

Examples

input

18 2

output

3 6 9

input

9 10

output

0 0 9

input

1000000000000 5

output

83333333333 416666666665 500000000002

input

1000000000000 499999999999

output

1 499999999999 500000000000

 

 

 

 

题意:

总学生人数为n,就是获证书的人数为x,获文凭的人数为y,输出x,y和没有获奖的人数z,有两个要求如下:

x>=y*k

x+y<=n/2

分析:两种情况

没人获奖时:获奖的最低限度是一人获奖:也就是1+k<=n/2,自然1+ k>n/2就是没人获奖的情况0输出 0, 0,n就可以

有人获奖时:最大限度就是取等号的时候也就是x=y*k,x+y=n/2 => y=(n/2)/(k+1),x=k*y,z=n-(x+y);

Code:

 

#include<stdio.h>
#define ll long long
using namespace std;
ll n,k;
int main()
{
    while(~scanf("%lld%lld",&n,&k))
    {
        ll x=n/2;
        if(1+k>x)
            printf("0 0 %lld\n",n);
        else
        {
             x=x/(k+1);
            ll y=k*x;
            ll z=n-(x+y);
            printf("%lld %lld %lld\n",x,y,z);
        }
    }
    return 0;
}




 

 

 

 

 

 

 

 

B. Permutation Game

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.

The game consists of m steps. On each step the current leader with index i counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.

You are given numbers l1, l2, ..., lm — indices of leaders in the beginning of each step. Child with number l1 is the first leader in the game.

Write a program which will restore a possible permutation a1, a2, ..., an. If there are multiple solutions then print any of them. If there is no solution then print -1.

Input

The first line contains two integer numbers nm (1 ≤ n, m ≤ 100).

The second line contains m integer numbers l1, l2, ..., lm (1 ≤ li ≤ n) — indices of leaders in the beginning of each step.

Output

Print such permutation of n numbers a1, a2, ..., an that leaders in the game will be exactly l1, l2, ..., lm if all the rules are followed. If there are multiple solutions print any of them.

If there is no permutation which satisfies all described conditions print -1.

Examples

input

4 5
2 3 1 4 4

output

3 1 2 4 

input

3 3
3 1 2

output

-1

Note

Let's follow leadership in the first example:

  • Child 2 starts.
  • Leadership goes from 2 to 2 + a2 = 3.
  • Leadership goes from 3 to 3 + a3 = 5. As it's greater than 4, it's going in a circle to 1.
  • Leadership goes from 1 to 1 + a1 = 4.
  • Leadership goes from 4 to 4 + a4 = 8. Thus in circle it still remains at 4.

 

题意:有n个人每个人对应一个a[i](1<=a[i]<=n,并且每个a[i]不重复),给你一个序列 l[1]~l[m]表示a[l[i]]+l[i]=l[i+1],要求求出a这个序列

 

分析:首先考虑找不到每个a[i]的情况:

1.存在a[l[i]有多个不一样的值

2.存在当前a[l[i]]==0时l[i]已经被使用

3.最后找不到未被使用的j(1<=j<n),使得 a[i]找不到对应的值

Code:

#include<stdio.h>
#include<string.h>
using namespace std;
int n,m;
int b[110];
int a[110];
int vis[110];
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1; i<=m; i++)
            scanf("%d",&b[i]);
        memset(vis,0,sizeof(vis));
        memset(a,0,sizeof(a));
        int flag=0;
        for(int i=1; i<m; i++)
        {
            int x=b[i+1]-b[i];
            if(x<=0)
                x+=n;
            if(a[b[i]]==0&&!vis[x])
            {
                a[b[i]]=x;
                vis[x]=1;
            }
            else if(a[b[i]]==0&&vis[x])
            {
                flag=1;
                //printf("hhhhhhhh\n");
            }
            if(a[b[i]]!=x)
            {
                //printf("%d %d\n",a[b[i]],x);
                //printf("aaaaaaa\n");
                flag=1;
            }
        }
        for(int i=1; i<=n; i++)
        {
            if(!a[i])
            {
                for(int j=1; j<=n; j++)
                {
                    if(!vis[j])
                    {
                        vis[j]=1;
                        a[i]=j;
                        break;
                    }
                }
            }
        }
        if(flag)
            printf("-1\n");
        else
            for(int i=1; i<=n; i++)
                i==n?printf("%d\n",a[i]):printf("%d ",a[i]);
    }
    return 0;
}

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值