Codeforces Round #523 (Div. 2)

Codeforces Round #523 (Div. 2)

Coins 

 

 

 

 

 

 

 

 

 

You have unlimited number of coins with values 1,2,…,n1,2,…,n . You want to select some set of coins having the total value of SS .

It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum SS ?

Input

The only line of the input contains two integers nn and SS (1≤n≤1000001≤n≤100000 , 1≤S≤1091≤S≤109 )

Output

Print exactly one integer — the minimum number of coins required to obtain sum SS .

Examples

Input

 

5 11

Output

 

3

Input

 

6 16

Output

 

3

Note

In the first example, some of the possible ways to get sum 1111 with 33 coins are:

  • (3,4,4)(3,4,4)
  • (2,4,5)(2,4,5)
  • (1,5,5)(1,5,5)
  • (3,3,5)(3,3,5)

It is impossible to get sum 1111 with less than 33 coins.

In the second example, some of the possible ways to get sum 1616 with 33 coins are:

  • (5,5,6)(5,5,6)
  • (4,6,6)(4,6,6)

It is impossible to get sum 1616 with less than 33 coins.

【题意】:

水题。大水题,开场8分钟就有3000+了,大家读读题意就可以做出来了。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,S;
    scanf("%d%d",&n,&S);
    int ans=ceil((S*1.0)/(n*1.0));
    printf("%d\n",ans);
    return 0;
}

 

B. Views Matter

 

 

 

 

 

 

 

You came to the exhibition and one exhibit has drawn your attention. It consists of nn stacks of blocks, where the ii -th stack consists of aiai blocks resting on the surface.

The height of the exhibit is equal to mm . Consequently, the number of blocks in each stack is less than or equal to mm .

There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.

Find the maximum number of blocks you can remove such that the views for both the cameras would not change.

Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either.

Input

The first line contains two integers nn and mm (1≤n≤100000 , 1≤m≤1e9 ) — the number of stacks and the height of the exhibit.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤m ) — the number of blocks in each stack from left to right.

Output

Print exactly one integer — the maximum number of blocks that can be removed.

 

Input

 

5 6
3 3 3 3 3

Output

 

10

Input

 

3 5
1 2 4

Output

 

3

Input

 

5 5
2 3 1 4 4

Output

 

9

Input

 

1 1000
548

Output

 

0

Input

 

3 3
3 1 1

Output

 

1

Note

The following pictures illustrate the first example and its possible solution.

Blue cells indicate removed blocks. There are 10 blue cells, so the answer is 10 .


【题意】:

题意就是给你一排的高度,然后保证他们的三视图中,俯视图和侧视图不变,问你最大能移动多少块方格。

然后这些方格是可以悬浮的,题目说了,不算重力的作用,也就是可以空中浮动。

具体看题目给的示例。

【题解】:

贪心即可,你只要想想就是了,首先排序,因为只看侧视图,所以排序了你也不用担心。

然后排序后,你其实用贪心的想法就可以做了,

[1,n-1] 堆中,只保留一个方格,记住这个方格是可以悬浮的,所以让他悬浮,并且是递增的。

然后如果原堆中无法保证他递增,那么只能保持最大高度即可。

然后考虑最后一个堆。

只要在倒数第二个堆覆盖的高度减去。那么答案就出来了。

如果看不懂题解。可以直接看代码理解。我认为这题看代码也能看懂这个贪心思想。

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int a[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);

    ll ans=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    if(n==1){
        return 0*printf("0\n");
    }
    sort(a,a+n);
    int cnt=0;
    for(int i=0;i<n-1;i++){
        ans+=(a[i]-1);
        if(a[i]>=(cnt+1)){
            cnt++;
        }
    }
    ans+=(cnt);
    if(a[n-1]==cnt){
        ans--;
    }
    printf("%lld\n",ans);
    return 0;
}

Multiplicity

You are given an integer array a1,a2,…,an .

The array bb is called to be a subsequence of aa if it is possible to remove some elements from aa to get bb .

Array b1,b2,…,bk is called to be good if it is not empty and for every ii (1≤i≤k ) bibi is divisible by ii .

Find the number of good subsequences in aa modulo 1e9+7 .

Two subsequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, the array aa has exactly 2^n−1 different subsequences (excluding an empty subsequence).

Input

The first line contains an integer n(1≤n≤100000 ) — the length of the array aa .

The next line contains integers a1,a2,…,an(1≤ai≤1e6 ).

Output

Print exactly one integer — the number of good subsequences taken modulo 109+7109+7 .

Examples

Input

 

2
1 2

Output

 

3

Input

 

5
2 2 1 22 14

Output

 

13

Note

In the first example, all three non-empty possible subsequences are good: {1} , {1,2} , {2}

In the second example, the possible good subsequences are: {2} , {2,2} , {2,22} , {2,14} , {2} , {2,22} ,{2,14} ,{1} , {1,22} , {1,14} , {22} , {22,14} ,{14} .

Note, that some subsequences are listed more than once, since they occur in the original array multiple times.

【题意】:

给你一个序列,求出所有子序列,这个子序列满足  对应位置 i,a[i]%i==0

具体可以看示例

【题解】:

这个是我赛后看别人代码想到的,我在做题时,以为可以深搜记忆化搜索。想太多了。

其实这个题目 考察的是因子,首先把某个数a[i] 的因子全部找出来,然后其实这个数,可以在它因子的 i  的位置。

也就是 i 是 它的一个因子,然后只要从前面的一个状态的, i-1 的位置叠加,那么这个题的答案就是所有数字,

可以在的所有位置时的和。自己慢慢研究吧。

正解是这个代码:

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define X first
#define Y second
#include<ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
vector<int>dd[maxn];
void init(){
    for(int i=1;i<maxn;++i)
        for(int j=i;j<maxn;j+=i)
        dd[j].push_back(i);
    for(int i=1;i<maxn;++i)
        reverse(dd[i].begin(),dd[i].end());
}
int add(int x,int y){
    if((x+=y)>=mod)return x-mod;
    return x;
}
int en[maxn],a[maxn];
int main() {
#ifdef local
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    init();
    int n;cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    en[0]=1;
    for(int i=1,now=0;i<=n;++i,now^=1){
        int val=a[i];
        for(int d:dd[val]){
            if(en[d-1])
            en[d]=add(en[d],en[d-1]);
        }
    }
    int ans=0;
    for(int i=1;i<maxn;++i)
        ans=add(ans,en[i]);
    cout<<ans;


    return 0;
}

第二个代码是自己看着写的(抄的);

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e6+10;
const int maxn=N;
vector<int>vec[N];
int dp[N];
void init(){
    for(int i=1;i<N;i++){
        for(int j=i;j<N;j+=i){
            vec[j].push_back(i);
        }
    }
    for(int i=1;i<N;i++){
        reverse(vec[i].begin(),vec[i].end());
    }
}
int n,a[N];
int main()
{
    init();
    ll ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    dp[0]=1;
    for(int i=0;i<n;i++){
        for(auto t:vec[a[i]]){
            if(dp[t-1]){
                dp[t]=(dp[t]+dp[t-1])%mod;
            }
        }
    }
    for(int i=1;i<N;i++){
        ans=(ans+dp[i])%mod;
    }
    printf("%d\n",ans);
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值