CodeForces 525C . Ilya and Sticks
2016-09-11 17:50
399 查看
C. Ilya and Sticks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks
and an instrument. Each stick is characterized by its length li.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of
sticks remain unused. Bending sticks is not allowed.
Sticks with lengths a1, a2, a3 and a4 can
make a rectangle if the following properties are observed:
a1 ≤ a2 ≤ a3 ≤ a4
a1 = a2
a3 = a4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4.
A rectangle cannot be made of, for example, sticks5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can
either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the
number of the available sticks.
The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the
lengths of the sticks.
Output
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
Examples
input
output
input
output
input
output
题意:有N条木棍,求用这n条木棍可得到的所有矩形的最大面积(其中木棍的长度可以减少1)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks
and an instrument. Each stick is characterized by its length li.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of
sticks remain unused. Bending sticks is not allowed.
Sticks with lengths a1, a2, a3 and a4 can
make a rectangle if the following properties are observed:
a1 ≤ a2 ≤ a3 ≤ a4
a1 = a2
a3 = a4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4.
A rectangle cannot be made of, for example, sticks5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can
either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the
number of the available sticks.
The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the
lengths of the sticks.
Output
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
Examples
input
4 2 4 4 2
output
8
input
4 2 2 3 5
output
0
input
4 100003 100004 100005 100006
output
10000800015
题意:有N条木棍,求用这n条木棍可得到的所有矩形的最大面积(其中木棍的长度可以减少1)
#include<stdio.h> #include<string.h> #include<algorithm> #define LL long long using namespace std; int a[100000+10]; int main() { int n,i,j,k,l; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); bool flag=false; LL ans=0; for(i=n-1;i>=1;i--) { if(a[i+1]-a[i]<2) { if(!flag) { k=a[i]; flag=true; } else { ans+=(LL)k*a[i]; flag=false; } i--; } } printf("%lld\n",ans); } return 0; }
相关文章推荐
- Codeforces 525C:Ilya and Sticks
- Codeforces 525C. Ilya and Sticks
- codeforces 525C Ilya and Sticks
- Codeforces_round297_C. Ilya and Sticks
- CF 525C(Ilya and Sticks-贪心)
- CF_525C_IlyaAndSticks
- Code Forces 525C Ilya and Sticks
- Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
- Codeforces Round #297 (Div. 2) C - Ilya and Sticks
- Codeforces 842C Ilya And The Tree
- codeforces 303 D. Ilya and Roads(动态规划)
- #297 (div.2) C. Ilya and Sticks
- codeforces 525C Ilya and Sticks(简单贪心)
- 【55.70%】【codeforces 557A】Ilya and Diplomas
- C. Ilya and Sticks(Codeforces Round 297(div2))
- codeforces 313C. Ilya and Matrix
- Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)
- codeforces--518D--Ilya and Escalator--概率DP
- Codeforces 518D Ilya and Escalator (概率dp)
- Codeforces Round #297 (Div. 2) C. Ilya and Sticks 解题报告