h_nosonの日記

競プロ、CTFなど

Codeforces Round #349 (Div. 2) B. Coat of Anticubism

問題
Problem - B - Codeforces
棒がN本あり,それぞれの長さはL_iである.
それらを繋げても多角形を作ることが出来ない.
1本棒を加えるとき,多角形を作るために必要な最短の長さは幾つか.

解法
L_iの最大値をmとした時,
その他の棒を合わせてm+1が得られれば多角形が作れる.

ソースコード

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

int main() {
    int i, n, ans;
    int l[100000];
    cin >> n;
    rep (i,n) cin >> l[i];
    auto mx = max_element(l,l+n);
    ans = *mx+1;
    rep (i,n) if (l+i != mx) ans -= l[i];
    cout << ans << endl;
    return 0;
}

この回は全体的に英語がわかりにくく,無駄な文章も多かったので辛かった.