Educational Codeforces Round 85 (Rated for Div. 2)题解

在这里插入图片描述
写在前面: 没想到思路全对的情况下居然因为一个初始化错误卡了一个多小时没出来。。。

A. Level Statistics

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.

All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by 1. If he manages to finish the level successfully then the number of clears increases by 1 as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).

Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.

So he peeked at the stats n times and wrote down n pairs of integers — (p1,c1),(p2,c2),…,(pn,cn), where pi is the number of plays at the i-th moment of time and ci is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).

Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.

Finally, Polycarp wonders if he hasn’t messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.

Help him to check the correctness of his records.

For your convenience you have to answer multiple independent test cases.

Input
The first line contains a single integer T (1≤T≤500) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤100) — the number of moments of time Polycarp peeked at the stats.

Each of the next n lines contains two integers pi and ci (0≤pi,ci≤1000) — the number of plays and the number of clears of the level at the i-th moment of time.

Note that the stats are given in chronological order.

Output
For each test case print a single line.

If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print “YES”.

Otherwise, print “NO”.

You can print each letter in any case (upper or lower).

Example
inputCopy
6
3
0 0
1 1
1 2
2
1 0
1000 3
4
10 1
15 2
10 2
15 2
1
765 432
2
4 4
4 3
5
0 0
1 0
1 0
1 0
1 0
outputCopy
NO
YES
NO
YES
NO
YES
Note
In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn’t have happened.

The second test case is a nice example of a Super Expert level.

In the third test case the number of plays decreased, which is impossible.

The fourth test case is probably an auto level with a single jump over the spike.

In the fifth test case the number of clears decreased, which is also impossible.

Nobody wanted to play the sixth test case; Polycarp’s mom attempted it to make him feel better, however, she couldn’t clear it.
思路:
简单判断,三个条件。

#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
 
typedef long long ll;
 
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
 
        int f = 0;
 
        int p[1005] = {0}, c[1005] = {0};
 
        for (int i = 1; i <= n; ++i)
        {
            int x, y;
            cin >> p[i] >> c[i];
            if (p[i] < p[i - 1] || c[i] < c[i - 1] || (c[i] - c[i - 1] > p[i] - p[i - 1]))
                f = 1;
        }
        if (f)
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
    }
 
    return 0;
}

B. Middle Class

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Many years ago Berland was a small country where only n people lived. Each person had some savings: the i-th one had ai burles.

The government considered a person as wealthy if he had at least x burles. To increase the number of wealthy people Berland decided to carry out several reforms. Each reform looked like that:

the government chooses some subset of people (maybe all of them);
the government takes all savings from the chosen people and redistributes the savings among the chosen people equally.
For example, consider the savings as list [5,1,2,1]: if the government chose the 1-st and the 3-rd persons then it, at first, will take all 5+2=7 burles and after that will return 3.5 burles to the chosen people. As a result, the savings will become [3.5,1,3.5,1].

A lot of data was lost from that time, so we don’t know how many reforms were implemented and to whom. All we can do is ask you to calculate the maximum possible number of wealthy people after several (maybe zero) reforms.

Input
The first line contains single integer T (1≤T≤1000) — the number of test cases.

Next 2T lines contain the test cases — two lines per test case. The first line contains two integers n and x (1≤n≤105, 1≤x≤109) — the number of people and the minimum amount of money to be considered as wealthy.

The second line contains n integers a1,a2,…,an (1≤ai≤109) — the initial savings of each person.

It’s guaranteed that the total sum of n doesn’t exceed 105.

Output
Print T integers — one per test case. For each test case print the maximum possible number of wealthy people after several (maybe zero) reforms.

Example
inputCopy
4
4 3
5 1 2 1
4 10
11 9 11 9
2 5
4 3
3 7
9 4 9
outputCopy
2
4
0
3
Note
The first test case is described in the statement.

In the second test case, the government, for example, could carry out two reforms: [11–––,9–,11,9]→[10,10,11–––,9–]→[10,10,10,10].

In the third test case, the government couldn’t make even one person wealthy.

In the fourth test case, the government could choose all people to carry out a reform: [9–,4–,9–]→[713,713,713].
思路:
排序取和求平均,大于等于要求即可。

#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
 
typedef long long ll;
 
ll a[100004];
 
bool cmp(ll x, ll y)
{
    return x > y;
}
 
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        ll n, m;
 
        cin >> n >> m;
 
        for (int i = 0; i < n; ++i)
            cin >> a[i];
 
        sort(a, a + n, cmp);
 
        double sum = 0;
        ll cnt = 0;
 
        for (int i = 0; i < n; ++i)
        {
            sum += a[i];
            double avl = sum * 1.0 / (cnt + 1);
            if (avl >= m)
                cnt++;
            else
                break;
        }
        cout << cnt << endl;
    }
 
    return 0;
}

C. Circle of Monsters

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are playing another computer game, and now you have to slay n monsters. These monsters are standing in a circle, numbered clockwise from 1 to n. Initially, the i-th monster has ai health.

You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monster by 1 (deals 1 damage to it). Furthermore, when the health of some monster i becomes 0 or less than 0, it dies and explodes, dealing bi damage to the next monster (monster i+1, if i<n, or monster 1, if i=n). If the next monster is already dead, then nothing happens. If the explosion kills the next monster, it explodes too, damaging the monster after it and possibly triggering another explosion, and so on.

You have to calculate the minimum number of bullets you have to fire to kill all n monsters in the circle.

Input
The first line contains one integer T (1≤T≤150000) — the number of test cases.

Then the test cases follow, each test case begins with a line containing one integer n (2≤n≤300000) — the number of monsters. Then n lines follow, each containing two integers ai and bi (1≤ai,bi≤1012) — the parameters of the i-th monster in the circle.

It is guaranteed that the total number of monsters in all test cases does not exceed 300000.

Output
For each test case, print one integer — the minimum number of bullets you have to fire to kill all of the monsters.

Example
inputCopy
1
3
7 15
2 14
5 3
outputCopy
6
思路:
我把一个最主要的初始化位置搞错了。。。而且这题容易TLE,关了输入输出流和endl就过了。
每一个和上一位做差就是必须要的子弹数目,然后找最小的一位为起点。

#include <iostream>
 
using namespace std;
 
typedef long long ll;
#define endl '\n'
ll a[300004];
ll b[300004];
ll c[300004];
 
ll maxp = 999999999999;
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
 
        int pos = 0;
 
        ll xs = 0;
 
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i] >> b[i];
            if (i > 0 && b[i - 1] > a[i])
                b[i - 1] = a[i];
            if (i > 0)
            {
                c[i] = a[i] - b[i - 1];
            }
        }
 
        if (a[0] < b[n - 1]) b[n - 1] = a[0];
        c[0] = a[0] - b[n - 1];
        
         maxp = a[0] - c[0];
 
        for (int i = 0; i < n; ++i)
        {
            xs += c[i];
            if (maxp > a[i] - c[i])
            {
                maxp = a[i] - c[i];
                pos = i;
            }
        }
 
        cout << xs + a[pos] - c[pos] << endl;
    }
    return 0;
}
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值