Sicily 13060. Queen Dido’s New Challenge

13060. Queen Dido’s New Challenge

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Queen Dido of Carthage (850 BC) solved the first isoperimetric problem. She was promised as much land along the coast as she could enclose with an ox hide. According to the legend, she cut up a bull's hide into very thin strips which she sewed together into one long string. Then she took the seashore as one edge for the piece of land and laid the skin into a semicircle. Modern calculus of variations would prove that Queen Dido’s solution is optimal and with a fixed string length the semicircle encloses maximum area along a straight coastline.

Now Queen Dido was facing a new challenge. Given a bunch of twigs of various lengths, she needed to form a triangle along the coast to enclose the largest possible area.

One side of the triangle was the seashore and would not use any twigs. The other two sides should be formed by laying the twigs. The twigs could not be cut down further.

Input

Each input line consists of a positive integer n (2<=n<=100), the number of twigs, followed by n positive integers representing the lengths of the twigs:

n L1 L2 ... Ln

The sum of the twig lengths is odd and L1+L2+...+Ln<100000.

Output

For each input line, print the area of the largest triangle, rounded to the nearest integer.

Sample Input

3 4 2 5
4 1 3 7 10
4 3 3 8 11

Sample Output

15
55
77

Problem Source

2014年每周一赛第十五场暨“指点传媒杯”第六届中山大学ICPC新手赛模拟赛

// Problem#: 13060
// Submission#: 3417262
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string.h>
#include <math.h>
#include <list>
using namespace std;

bool ok[100005];

int main() {

    std::ios::sync_with_stdio(false);

    while (1) {
        int N;
        cin >> N;
        if (cin.eof()) break;
        int sum = 0, temp;
        ok[0] = true;
        for (int i = 0; i < N; i++) {
            cin >> temp;
            for (int j = sum; j >= 0; j--) {
                if (ok[j]) ok[j + temp] = true;
            }
            sum += temp;
        }
        for (int i = sum / 2; i >= 0; i--) {
            if (ok[i]) {
                cout << (long long)i * (sum - i) / 2 << endl;
                break;
            }
        }
        for (int i = 1; i <= sum; i++) ok[i] = false;
    }

    return 0;
}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值