Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0

来源:互联网 发布:淘宝商城的商品特色 编辑:程序博客网 时间:2024/06/16 08:24
A. Between the Offices
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.

You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.

Input

The first line of input contains single integer n (2 ≤ n ≤ 100) — the number of days.

The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.

Output

Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.

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

Examples
input
4FSSF
output
NO
input
2SF
output
YES
input
10FFFFFFFFFF
output
NO
input
10SSFFSFFSFF
output
YES
Note

In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".

In the second example you just flew from Seattle to San Francisco, so the answer is "YES".

In the third example you stayed the whole period in San Francisco, so the answer is "NO".

In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.

水题

代码:

#include<bits/stdc++.h>using namespace std;char res[105];int main(){    int n,sf=0,fs=0;    cin>>n;    cin>>res;    for(int i=0;i<n-1;i++)    {        if(res[i]=='S'&&res[i+1]=='F')            sf++;        if(res[i]=='F'&&res[i+1]=='S')            fs++;    }    if(sf>fs)        printf("YES\n");    else        printf("NO\n");    return 0;}

B. Save the problem!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.

People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?

As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.

Input

Input will consist of a single integer A (1 ≤ A ≤ 105), the desired number of ways.

Output

In the first line print integers N and M (1 ≤ N ≤ 106, 1 ≤ M ≤ 10), the amount of change to be made, and the number of denominations, respectively.

Then print M integers D1, D2, ..., DM (1 ≤ Di ≤ 106), the denominations of the coins. All denominations must be distinct: for any i ≠ j we must have Di ≠ Dj.

If there are multiple tests, print any of them. You can print denominations in atbitrary order.

Examples
input
18
output
30 41 5 10 25
input
3
output
20 25 2
input
314
output
183 46 5 2 139

思路:

就是找个规律,只用1和2就能组成所需的答案。


代码:

#include<cstdio>int main(){    int a;    scanf("%d",&a);    printf("%d 2\n1 2\n",a==1?1:(a-1)*2);    return 0;}


C. Ordering Pizza
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.

It is known that the i-th contestant will eat si slices of pizza, and gain ai happiness for each slice of type 1 pizza they eat, and bi happiness for each slice of type 2 pizza they eat. We can order any number of type 1 and type 2 pizzas, but we want to buy the minimum possible number of pizzas for all of the contestants to be able to eat their required number of slices. Given that restriction, what is the maximum possible total happiness that can be achieved?

Input

The first line of input will contain integers N and S (1 ≤ N ≤ 105, 1 ≤ S ≤ 105), the number of contestants and the number of slices per pizza, respectively. N lines follow.

The i-th such line contains integers siai, and bi (1 ≤ si ≤ 105, 1 ≤ ai ≤ 105, 1 ≤ bi ≤ 105), the number of slices the i-th contestant will eat, the happiness they will gain from each type 1 slice they eat, and the happiness they will gain from each type 2 slice they eat, respectively.

Output

Print the maximum total happiness that can be achieved.

Examples
input
3 123 5 74 6 75 9 5
output
84
input
6 107 4 75 8 812 5 86 11 63 3 75 9 6
output
314
Note

In the first example, you only need to buy one pizza. If you buy a type 1 pizza, the total happiness will be 3·5 + 4·6 + 5·9 = 84, and if you buy a type 2 pizza, the total happiness will be 3·7 + 4·7 + 5·5 = 74.

题意:

有N个参赛者,需要准备披萨,有两种披萨,每一种披萨都有S片,分配给这些参赛者,每一个参赛者需要吃的披萨数量不定,接下来N行是每一个参赛者的信息,分别是需要吃的片数,吃了第一种获得的幸福感,吃了第二种披萨的幸福感。求用最少的可以满足这些需求的披萨,求出其中最大的幸福值。

代码:

#include<bits/stdc++.h>using namespace std;typedef long long ll;vector< pair<ll,ll> >a,b;ll n,s,ans,na,nb,ta,tb;signed main(){ll ss,aa,bb;pair<ll,ll>k;scanf("%I64d%I64d",&n,&s);for(int i=1;i<=n;i++){scanf("%lld%lld%lld",&ss,&aa,&bb);if(aa>bb){ans+=ss*aa;na+=ss;k.first=aa-bb;k.second=ss;a.push_back(k);}else{ans+=ss*bb;nb+=ss;k.first=bb-aa;k.second=ss;b.push_back(k);}}cout<<na<<"     "<<nb<<endl;na%=s;nb%=s;cout<<ans<<endl;if(na+nb>s){printf("%lld\n",ans);return 0;}sort(a.begin(),a.end());sort(b.begin(),b.end());for(int i=0;na;i++){ta+=min(na,a[i].second)*a[i].first;na-=min(na,a[i].second);cout<<"ta "<<ta<<"     "<<"na "<<na<<endl;}for(int i=0;nb;i++){tb+=min(nb,b[i].second)*b[i].first;nb-=min(nb,b[i].second);cout<<"tb "<<tb<<"     "<<"nb "<<nb<<endl;}ans-=min(ta,tb);printf("%I64d\n",ans);return 0;}


D. Buy Low Sell High
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the N days you would like to again own zero shares, but want to have as much money as possible.

Input

Input begins with an integer N (2 ≤ N ≤ 3·105), the number of days.

Following this is a line with exactly N integers p1, p2, ..., pN (1 ≤ pi ≤ 106). The price of one share of stock on the i-th day is given by pi.

Output

Print the maximum amount of money you can end up with at the end of N days.

Examples
input
910 5 4 7 9 12 6 2 10
output
20
input
203 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
output
41
Note

In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is  - 5 - 4 + 9 + 12 - 2 + 10 = 20.

题意:

已知每一天的某种股票的价钱,每天只能处理一股,希望最后手里没有股票,可以出卖股票和买进股票。

问你最后最多可以获得多少钱。

代码:

#include <bits/stdc++.h>using namespace std;int main(){int n;cin>>n;long long ans=0;int u;priority_queue<int>q;for(int i=1;i<=n;i++){cin>>u;q.push(-u);q.push(-u);ans+=u+q.top();cout<<ans<<endl;q.pop();}cout<<ans<<endl;return 0;}