Created
May 3, 2017 03:19
-
-
Save whatalnk/cba3f1fe4a5043828cbb731c56ad40d7 to your computer and use it in GitHub Desktop.
アリ本 1-6 p21 三角形
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
const int MAX_N = 50; | |
int n, a[MAX_N]; | |
void solve(){ | |
int ans = 0; | |
for (int i = 0; i < n; i++){ | |
for (int j = i + 1; j < n; j++){ | |
for (int k = j + 1; k < n; k++){ | |
int len = a[i] + a[j] + a[k]; | |
int ma = max({a[i], a[j], a[k]}); | |
int rest = len - ma; | |
if (ma < rest){ | |
ans = max(ans, len); | |
} | |
} | |
} | |
} | |
printf("%d\n", ans); | |
} | |
int main(){ | |
scanf("%d", &n); | |
for (int i = 0; i < n; i++){ | |
scanf("%d", &a[i]); | |
} | |
solve(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment