您的位置:首页 > 其它

Codeforces Round #274 (Div. 2)

2014-10-20 23:14 423 查看
A. Expression

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on
the blackboard. The task was to insert signs of operations '+' and '*',
and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:

1+2*3=7

1*(2+3)=5

1*2*3=6

(1+2)*3=9
Note that you can insert operation signs only between a and b,
and between b and c, that is, you cannot swap integers.
For instance, in the given sample you cannot get expression (1+3)*2.

It's easy to see that the maximum value that you can obtain is 9.

Your task is: given a, b and c print
the maximum value that you can get.

Input

The input contains three integers a, b and c,
each on a single line (1 ≤ a, b, c ≤ 10).

Output

Print the maximum value of the expression that you can obtain.

Sample test(s)

input
1
2
3


output
9


input
2
10
3


output
60


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#define rt return
#define bk break
#define ct continue
#define sf scanf
#define pf printf
#define ms memset
#define si(n) sf("%d",&n)
#define pi(n) pf("%d\n",n)
#define REP0(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,s,n) for(int i=s;i<=(n);i++)
#define db double
#define op operator
#define pb push_back
#define LL long long
#define INF 0x3fffffff
#define eps 1e-8
#define PI acos(-1)
#define maxn 1010
using namespace std;
int main(){
#ifdef ACBang
// freopen("in.txt","r",stdin);
#endif
int a,b,c;
while(~sf("%d%d%d",&a,&b,&c)){
int ans=0;
ans=max(ans,a*b*c);
ans=max(ans,(a+b)*c
11fa1
);
ans=max(ans,a+b*c);
ans=max(ans,a*(b+c));
ans=max(ans,a*b+c);
ans=max(ans,a+b+c);
pi(ans);
}
rt 0;
}


B. Towers

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists
of ai cubes
stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highest and the lowest of the towers. For example,
if Petya built five cube towers with heights (8, 3, 2, 6, 3), the instability of this set is equal to 6 (the highest tower has height 8, the lowest one has height 2).

The boy wants the instability of his set of towers to be as low as possible. All he can do is to perform the following operation several times: take the top cube from some tower and put it on top of some other tower of his set. Please note that Petya would
never put the cube on the same tower from which it was removed because he thinks it's a waste of time.

Before going to school, the boy will have time to perform no more than k such operations. Petya does not want to be late for class, so you have to help him
accomplish this task.

Input

The first line contains two space-separated positive integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000)
— the number of towers in the given set and the maximum number of operations Petya can perform. The second line contains n space-separated positive integers ai (1 ≤ ai ≤ 104)
— the towers' initial heights.

Output

In the first line print two space-separated non-negative integers s and m (m ≤ k).
The first number is the value of the minimum possible instability that can be obtained after performing at most k operations, the second number is the number
of operations needed for that.

In the next m lines print the description of each operation as two positive integers i and j,
each of them lies within limits from 1 to n. They represent
that Petya took the top cube from the i-th tower and put in on the j-th
one (i ≠ j). Note that in the process of performing operations the heights of some towers can become equal to zero.

If there are multiple correct sequences at which the minimum possible instability is achieved, you are allowed to print any of them.

Sample test(s)

input
3 2
5 8 5


output
0 2
2 1
2 3


input
3 4
2 2 4


output
1 1
3 2


input
5 3
8 3 2 6 3


output
3 3
1 3
1 2
1 3


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#define rt return
#define bk break
#define ct continue
#define sf scanf
#define pf printf
#define ms memset
#define si(n) sf("%d",&n)
#define pi(n) pf("%d\n",n)
#define REP0(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,s,n) for(int i=s;i<=(n);i++)
#define db double
#define op operator
#define pb push_back
#define LL long long
#define INF 0x3fffffff
#define eps 1e-8
#define PI acos(-1)
#define maxn 1010
using namespace std;
int n,k;
int p[maxn];
struct node{
int a,b;
void out(){pf("%d %d\n",a,b); }
}que[maxn];
int main(){
#ifdef ACBang
// freopen("in.txt","r",stdin);
#endif
while(~sf("%d%d",&n,&k)){
REP0(i,n)si(p[i]);
int ans=INF;
int m=k;
int cnt=0;
while(1){
int h=0,l=INF;
int posh,posl;
for(int i=0;i<n;i++){
if(p[i]>h){
h=p[i];
posh=i;
}
if(p[i]<l){
l=p[i];
posl=i;
}
}
if(h-l<=1){
ans=h-l;
break;
}
ans=min(ans,p[posh]-p[posl]);
if(cnt>=k)
break;
p[posh]--;
p[posl]++;
que[cnt].a=posh;
que[cnt].b=posl;
cnt++;
}
pf("%d %d\n",ans,cnt);
for(int i=0;i<cnt;i++)
pf("%d %d\n",que[i].a+1,que[i].b+1);
}
rt 0;
}


C. Exams

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart
guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.

According to the schedule, a student can take the exam for the i-th subject on the day number ai.
However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai).
Thus, Valera can take an exam for the i-th subject either on day ai,
or on day bi.
All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.

Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes
exams so that all the records in his record book go in the order of non-decreasing date.

Input

The first line contains a single positive integer n (1 ≤ n ≤ 5000)
— the number of exams Valera will take.

Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109)
— the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

Output

Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.

Sample test(s)

input
3
5 2
3 1
4 2


output
2


input
3
6 1
5 24 3


output
6


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#define rt return
#define bk break
#define ct continue
#define sf scanf
#define pf printf
#define ms memset
#define si(n) sf("%d",&n)
#define pi(n) pf("%d\n",n)
#define REP0(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,s,n) for(int i=s;i<=(n);i++)
#define db double
#define op operator
#define pb push_back
#define LL long long
#define INF 0x3fffffff
#define eps 1e-8
#define PI acos(-1)
#define maxn 5001
using namespace std;
int n;
struct node{
int x,y;
void in(){sf("%d%d",&x,&y); }
}p[maxn];
bool cmp(node a,node b){
if(a.x==b.x)rt a.y<b.y;
rt a.x<b.x;
}
int main(){
#ifdef ACBang
// freopen("in.txt","r",stdin);
#endif
int n;
while(~sf("%d",&n)){
REP0(i,n)p[i].in();
sort(p,p+n,cmp);
int ans=p[0].y;
int i=1;
while(i<n){
while(i<n&&p[i].y==ans)i++;
if(i<n&&p[i].y>ans)ans=p[i].y;
else if(i<n&&p[i].y!=ans)ans=p[i].x;
i++;
}
pi(ans);
}
rt 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: