Codeforces Round #608 (Div. 2)

A. Suits

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.

The store does not sell single clothing items — instead, it sells suits of two types:

a suit of the first type consists of one tie and one jacket;
a suit of the second type consists of one scarf, one vest and one jacket.
Each suit of the first type costs e coins, and each suit of the second type costs f coins.

Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).

Input
The first line contains one integer a (1≤a≤100000) — the number of ties.

The second line contains one integer b (1≤b≤100000) — the number of scarves.

The third line contains one integer c (1≤c≤100000) — the number of vests.

The fourth line contains one integer d (1≤d≤100000) — the number of jackets.

The fifth line contains one integer e (1≤e≤1000) — the cost of one suit of the first type.

The sixth line contains one integer f (1≤f≤1000) — the cost of one suit of the second type.

Output
Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.

Examples
inputCopy
4
5
6
3
1
2
outputCopy
6
inputCopy
12
11
13
20
4
6
outputCopy
102
inputCopy
17
14
5
21
15
17
outputCopy
325
Note
It is possible to compose three suits of the second type in the first example, and their total cost will be 6. Since all jackets will be used, it’s impossible to add anything to this set.

The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is 9⋅4+11⋅6=102.

#include <bits/stdc++.h>
using namespace std;
int t,n;
long long a,b,c,d,e,f;
int main()
{
    cin>>a>>b>>c>>d>>e>>f;
    long long ans=0;
    if(e>f)
    {
        ans+=min(a,d)*e;
        d-=min(a,d);
        a-=min(a,d);
        ans+=min(d,min(b,c))*f;
    }
    else
    {
        ans+=min(d,min(b,c))*f;
        d-=min(d,min(b,c));
        ans+=min(a,d)*e;
    }
    cout<<ans<<endl;
    return 0;
}

B. Blocks

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.

You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).

You want to find a sequence of operations, such that they make all the blocks having the same color. You don’t have to minimize the number of operations, but it should not exceed 3⋅n. If it is impossible to find such a sequence of operations, you need to report it.

Input
The first line contains one integer n (2≤n≤200) — the number of blocks.

The second line contains one string s consisting of n characters, each character is either “W” or “B”. If the i-th character is “W”, then the i-th block is white. If the i-th character is “B”, then the i-th block is black.

Output
If it is impossible to make all the blocks having the same color, print −1.

Otherwise, print an integer k (0≤k≤3⋅n) — the number of operations. Then print k integers p1,p2,…,pk (1≤pj≤n−1), where pj is the position of the left block in the pair of blocks that should be affected by the j-th operation.

If there are multiple answers, print any of them.

Examples
inputCopy
8
BWWWWWWB
outputCopy
3
6 2 4
inputCopy
4
BWBB
outputCopy
-1
inputCopy
5
WWWWW
outputCopy
0
inputCopy
3
BWB
outputCopy
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is “BWWWWBBB”. Then change blocks 2 and 3, so the sequence is “BBBWWBB”. And finally, change blocks 4 and 5, so all blocks are black.

It is impossible to make all colors equal in the second example.

All blocks are already white in the third example.

In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is “BBW”), and then change blocks 1 and 2 (so all blocks are white).

#include <bits/stdc++.h>
using namespace std;
int t,n;
string s;
vector<int>ans;
bool f()
{
    for(int i=1;i<n;i++)
        if(s[i]!=s[i-1])return false;
    return true;
}
int main()
{
    cin>>n;
    cin>>s;
    if(f()){cout<<0<<endl;return 0;}
    int g=1;
    string s1=s;
    int i=0;
    while(i<n)
    {
        if(i+1<n&&s.substr(i,2)=="BB")
        {ans.push_back(i+1);i+=2;}
        else if(i+1<n&&s[i]=='B'&&s[i+1]=='W'){swap(s[i],s[i+1]);ans.push_back(i+1);i++;}
        else if(s[i]=='W'){i++;continue;}
        else {g=0;break;}
    }
    if(g==1)
    {
        cout<<ans.size()<<endl;
        for(auto i:ans)cout<<i<<" ";cout<<endl;return 0;
    }
    ans.clear();
    //cout<<666<<endl;
    i=0;g=1;s=s1;
    while(i<n)
    {
        if(i+1<n&&s.substr(i,2)=="WW")
            {ans.push_back(i+1);i+=2;}
        else if(i+1<n&&s[i]=='W'&&s[i+1]=='B'){swap(s[i],s[i+1]);ans.push_back(i+1);i++;}
        else if(s[i]=='B'){i++;}
        else {g=0;break;}
    }
    if(g==0)cout<<-1<<endl;
    else
    {
        cout<<ans.size()<<endl;
        for(auto i:ans)cout<<i<<" ";cout<<endl;return 0;
    }
    return 0;
}

C. Shawarma Tent

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.

The main school of the capital is located in (sx,sy). There are n students attending this school, the i-th of them lives in the house located in (xi,yi). It is possible that some students live in the same house, but no student lives in (sx,sy).

After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |sx−xi|+|sy−yi|.

The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student’s house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).

You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.

Input
The first line contains three integers n, sx, sy (1≤n≤200000, 0≤sx,sy≤109) — the number of students and the coordinates of the school, respectively.

Then n lines follow. The i-th of them contains two integers xi, yi (0≤xi,yi≤109) — the location of the house where the i-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.

Output
The output should consist of two lines. The first of them should contain one integer c — the maximum number of students that will buy shawarmas at the tent.

The second line should contain two integers px and py — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of px and py should be not less than 0 and not greater than 109.

Examples
inputCopy
4 3 2
1 3
4 2
5 1
4 1
outputCopy
3
4 2
inputCopy
3 100 100
0 0
0 0
100 200
outputCopy
2
99 100
inputCopy
7 10 12
5 6
20 23
15 4
16 5
4 54
12 1
4 15
outputCopy
4
10 11
Note
In the first example, If we build the shawarma tent in (4,2), then the students living in (4,2), (4,1) and (5,1) will visit it.

In the second example, it is possible to build the shawarma tent in (1,1), then both students living in (0,0) will visit it.

#include <bits/stdc++.h>
using namespace std;
int t,n;
int a[5],b[5];
int x,y,sx,sy;
int main()
{
    cin>>n>>sx>>sy;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        if(x==sx&&y<sy)b[4]++;
        else if(x==sx&&y>sy)b[2]++;
        else if(y==sy&&x<sx)b[3]++;
        else if(y==sy)b[1]++;
        else if(x<sx&&y<sy)a[4]++;
        else if(x<sx&&y>sy)a[3]++;
        else if(x>sx&&y>sy)a[2]++;
        else if(x>sx&&y<sy)a[1]++;
    }
    int ma=0;int ex,ey;
    if(a[1]+a[2]+b[1]>ma)
    {
        ma=a[1]+a[2]+b[1];
        ex=sx+1;
        ey=sy;
    }
    if(a[2]+a[3]+b[2]>ma)
    {
        ma=a[2]+a[3]+b[2];
        ex=sx;ey=sy+1;
    }
    if(a[3]+a[4]+b[3]>ma)
    {
        ma=a[3]+a[4]+b[3];
        ex=sx-1;ey=sy;
    }
    if(a[1]+a[4]+b[4]>ma)
    {
        ma=a[1]+a[4]+b[4];
        ex=sx;ey=sy-1;
    }
    if(ma==0)cout<<0<<endl;
    else
    {
        cout<<ma<<endl<<ex<<" "<<ey<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值