Codeforces Round #610 (Div. 2)

A. Temporarily unavailable

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp lives on the coordinate axis Ox and travels from the point x=a to x=b. It moves uniformly rectilinearly at a speed of one unit of distance per minute.

On the axis Ox at the point x=c the base station of the mobile operator is placed. It is known that the radius of its coverage is r. Thus, if Polycarp is at a distance less than or equal to r from the point x=c, then he is in the network coverage area, otherwise — no. The base station can be located both on the route of Polycarp and outside it.

Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from x=a to x=b. His speed — one unit of distance per minute.

Input
The first line contains a positive integer t (1≤t≤1000) — the number of test cases. In the following lines are written t test cases.

The description of each test case is one line, which contains four integers a, b, c and r (−108≤a,b,c≤108, 0≤r≤108) — the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.

Any of the numbers a, b and c can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.

Output
Print t numbers — answers to given test cases in the order they are written in the test. Each answer is an integer — the number of minutes during which Polycarp will be unavailable during his movement.

Example
inputCopy
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
outputCopy
7
0
4
0
30
5
4
0
3
Note
The following picture illustrates the first test case.

Polycarp goes from 1 to 10. The yellow area shows the coverage area of the station with a radius of coverage of 1, which is located at the point of 7. The green area shows a part of the path when Polycarp is out of coverage area.

#include<bits/stdc++.h>
using namespace std;
int n,t,a,b,c,r;
int main()
{
    cin>>t;
    while(t--)
    {
        int ans=b-a;
        cin>>a>>b>>c>>r;
        if(a>b)swap(a,b);
        int l=c-r,ri=c+r;
        if(ri<=a||l>=b)ans=b-a;
        else if(l<=a&&b<=ri)ans=0;
        else if(l>=a&&ri<=b)ans=b-a-2*r;
        else if(l>a)ans=l-a;
        else ans=b-ri;
        cout<<ans<<endl;
    }
    return 0;
}

B1 B2. K for the Price of One (Easy Version and Hard Version)

#include<bits/stdc++.h>
using namespace std;
int n,t,k;
long long a[200010],p;
long long dp[200010];
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>p>>k;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        int ans=0;
        for(int i=1;i<k;i++)dp[i]=dp[i-1]+a[i];
        for(int i=k;i<=n;i++)
        {
            dp[i]=dp[i-k]+a[i];
        }
        for(int i=1;i<=n;i++){if(p>=dp[i]){ans=i;}}
        cout<<ans<<endl;
    }
    return 0;
}

这次写的比较快 开心

C. Petya and Exam

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes.

The exam consists of n problems that can be solved in T minutes. Thus, the exam begins at time 0 and ends at time T. Petya can leave the exam at any integer time from 0 to T, inclusive.

All problems are divided into two types:

easy problems — Petya takes exactly a minutes to solve any easy problem;
hard problems — Petya takes exactly b minutes (b>a) to solve any hard problem.
Thus, if Petya starts solving an easy problem at time x, then it will be solved at time x+a. Similarly, if at a time x Petya starts to solve a hard problem, then it will be solved at time x+b.

For every problem, Petya knows if it is easy or hard. Also, for each problem is determined time ti (0≤ti≤T) at which it will become mandatory (required). If Petya leaves the exam at time s and there is such a problem i that ti≤s and he didn’t solve it, then he will receive 0 points for the whole exam. Otherwise (i.e if he has solved all such problems for which ti≤s) he will receive a number of points equal to the number of solved problems. Note that leaving at time s Petya can have both “mandatory” and “non-mandatory” problems solved.

For example, if n=2, T=5, a=2, b=3, the first problem is hard and t1=3 and the second problem is easy and t2=2. Then:

if he leaves at time s=0, then he will receive 0 points since he will not have time to solve any problems;
if he leaves at time s=1, he will receive 0 points since he will not have time to solve any problems;
if he leaves at time s=2, then he can get a 1 point by solving the problem with the number 2 (it must be solved in the range from 0 to 2);
if he leaves at time s=3, then he will receive 0 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
if he leaves at time s=4, then he will receive 0 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
if he leaves at time s=5, then he can get 2 points by solving all problems.
Thus, the answer to this test is 2.

Help Petya to determine the maximal number of points that he can receive, before leaving the exam.

Input
The first line contains the integer m (1≤m≤104) — the number of test cases in the test.

The next lines contain a description of m test cases.

The first line of each test case contains four integers n,T,a,b (2≤n≤2⋅105, 1≤T≤109, 1≤a<b≤109) — the number of problems, minutes given for the exam and the time to solve an easy and hard problem, respectively.

The second line of each test case contains n numbers 0 or 1, separated by single space: the i-th number means the type of the i-th problem. A value of 0 means that the problem is easy, and a value of 1 that the problem is hard.

The third line of each test case contains n integers ti (0≤ti≤T), where the i-th number means the time at which the i-th problem will become mandatory.

It is guaranteed that the sum of n for all test cases does not exceed 2⋅105.

Output
Print the answers to m test cases. For each set, print a single integer — maximal number of points that he can receive, before leaving the exam.

Example
inputCopy
10
3 5 1 3
0 0 1
2 1 4
2 5 2 3
1 0
3 2
1 20 2 4
0
16
6 20 2 5
1 1 0 1 0 0
0 8 2 9 11 6
4 16 3 6
1 0 1 1
8 3 5 6
6 20 3 6
0 1 0 0 1 0
20 11 3 20 16 17
7 17 1 6
1 1 0 1 0 0 0
1 7 0 11 10 15 10
6 17 2 6
0 0 1 0 0 1
7 6 3 7 10 12
5 17 2 5
1 1 1 1 0
17 11 10 6 4
1 1 1 2
0
1
outputCopy
3
2
1
0
1
4
0
1
2
1

#include<bits/stdc++.h>
using namespace std;
int n,t,x,y,v;
struct node
{
    int c;
    int t;
};
node a[200010];
bool cmp(node &s1,node &s2)
{
    return s1.t<s2.t;
}
long long dp[200010];int s[200010];
int main()
{
    cin>>t;
    while(t--)
    {
        int ans=0;
        cin>>n>>v>>x>>y;int b1=0,b2=0;for(int i=0;i<=n+2;i++){s[i]=0;dp[i]=0;a[i].c=a[i].t=0; }
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].c;
        }
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].t;
        }
        sort(a+1,a+1+n,cmp);
        for(int i=1;i<=n;i++)
        {
            if(a[i].c==0){dp[i]=dp[i-1]+x;b1++;}
            else {dp[i]=dp[i-1]+y;b2++;}
        }
        ans=min(((a[1].t-1)/x),b1);
        for(int i=1;i<=n;i++)
        {
            if(a[i].c==0)b1--;
            if(i==n)s[i]=0;
            else if(a[i+1].t>dp[i])
            s[i]=min((int)(a[i+1].t-dp[i]-1)/x,b1);
            else s[i]=0;
        }
        int k=ans;
        for(int i=1;i<=n;i++)
        {
            if(i==n){int f=y;if(a[i].c==0)f=x; if(v-dp[i-1]>=f){ans=i;k=i;}}
            else if(dp[i]<a[i+1].t){ans=i;}k=max(max(ans,ans+s[i]),k);
        }
        cout<<max(max(ans,k),0)<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值