Codeforces Round #643 (Div. 2)

B题

Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties…

Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter ei — his inexperience. Russell decided that an explorer with inexperience e can only join the group of e or more people.

Now Russell needs to figure out how many groups he can organize. It’s not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.

Input
The first line contains the number of independent test cases T(1≤T≤2⋅105). Next 2T lines contain description of test cases.

The first line of description of each test case contains the number of young explorers N (1≤N≤2⋅105).

The second line contains N integers e1,e2,…,eN (1≤ei≤N), where ei is the inexperience of the i-th explorer.

It’s guaranteed that sum of all N doesn’t exceed 3⋅105.

Output
Print T numbers, each number on a separate line.

In i-th line print the maximum number of groups Russell can form in i-th test case.

Example
inputCopy
2
3
1 1 1
5
2 3 1 2 2
outputCopy
3
2
Note
In the first example we can organize three groups. There will be only one explorer in each group. It’s correct because inexperience of each explorer equals to 1, so it’s not less than the size of his group.

In the second example we can organize two groups. Explorers with inexperience 1, 2 and 3 will form the first group, and the other two explorers with inexperience equal to 2 will form the second group.

This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to 2, and the second group using only one explorer with inexperience equal to 1. In this case the young explorer with inexperience equal to 3 will not be included in any group.
思考:这个题目自己在本子上都很容易就模拟出来可是到了写代码的时候总是有些地方处理不好,导致这个题木出来,明明有思路还做不出来真是可惜

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
using namespace std;
int a[200001];
int main()
{

    int t; cin >> t;
    while (t--)
    {
        int n; cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        sort(a+1, a+1+n);
        int ans = 0, s =0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] <= i - s)
            {
                s += a[i];
                ans++;
            }
        }
        cout << ans << endl;
    }
}

D题

D. Game With Array
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Petya and Vasya are competing with each other in a new interesting game as they always do.

At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0≤K≤S.

In order to win, Vasya has to find a non-empty subarray in Petya’s array such that the sum of all selected elements equals to either K or S−K. Otherwise Vasya loses.

You are given integers N and S. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

Input
The first line contains two integers N and S (1≤N≤S≤106) — the required length of the array and the required sum of its elements.

Output
If Petya can win, print “YES” (without quotes) in the first line. Then print Petya’s array in the second line. The array should contain N positive integers with sum equal to S. In the third line print K. If there are many correct answers, you can print any of them.

If Petya can’t win, print “NO” (without quotes).

You can print each letter in any register (lowercase or uppercase).

Examples
inputCopy
1 4
output
YES
4
2
input
3 4
output
NO
input
3 8
output
YES
2 1 5
4

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
using namespace std;
int a[20000000];
int main()
{
    int n, s; cin >> n >> s;
    for (int i = 1; i < n; i++)
        a[i] = 1;
    a[n] = s - n + 1;
    if (a[n] - (n - 1) > 1)
    {
        cout << "YES" << endl;
            for (int i = 1; i <= n; i++)
                cout << a[i] << " ";
        cout << endl;
        cout << n << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
   
}

或者是

cin>>n>>s;
	if(s<n*2) cout<<"NO"<<endl;
	else
	{
		cout<<"YES"<<endl;
		for(int i=1;i<=n-1;i++) cout<<1<<" ";
		cout<<s-(n-1)<<endl;
		cout<<n<<endl; 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值