Codeforces Round #393 (Div. 2) A+B

A. Petr and a calendar

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:

Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.

Input

The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).

Output

Print single integer: the number of columns the table should have.

Examples

Input
1 7

Output
6

Input
1 1

Output
5

Input
11 6

Output
5

Note

The first example corresponds to the January 2017 shown on the picture in the statements.

In the second example 1-st January is Monday, so the whole month fits into 5 columns.

In the third example 1-st November is Saturday and 5 columns is enough.
题意:在2017年中,m是月份 d是这个月第一天是星期几。问这个月的日历需要多少行。
代码:

#include <iostream>
using namespace std;
int main()
{
    int a[20]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int n,m;
    int sum=0;
    cin>>n>>m;
    a[n]-=abs(m-8);
    if(a[n]%7!=0)
    sum++;
    cout<<sum+a[n]/7+1<<endl;

}

B. Frodo and pillows

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

n hobbits are planning to spend the night at Frodo’s house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it’s not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.

Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?

Input

The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo’s bed.

Output

Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.

Examples

Input
4 6 2

Output
2

Input
3 10 3

Output
4

Input
3 6 1

Output
3

Note

In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.

In the second example Frodo can take at most four pillows, giving three pillows to each of the others.

In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed
题意:
n个小孩,m个枕头,你的位置在k。要求相邻的人的枕头数不能差1.问你的最多可以拥有的枕头数。
题解:二分
代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,ans,l,r;
ll sum(ll x,ll y)
{
    x=max(x,0ll);
    return (x+y)*(y-x+1ll)/2;
}
int  solve(ll mid)
{
    ll need=sum(mid-k+1,mid)+sum(mid-n+k,mid)-mid;
    if(need<=m) return 1;
    return 0;
}
int main()
{
    cin>>n>>m>>k;
    m-=n;
    l=0;
    r=m;
    while(r-l>=0)
    {
        ll mid=(r+l)>>1;
        if(solve(mid))
        {
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout<<ans+1<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值