Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <memory.h>
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <vector>
- #include <cmath>
- #include <map>
- #include <algorithm>
- #include <cstdio>
- #include <set>
- #include <list>
- #include <queue>
- #define y1 vamdlsfmvldf
- using namespace std;
- #define mp make_pair
- typedef long long ll;
- const ll mod = 1000000009;
- const int inf = (int)(1e9 + 7);
- const double pi = 3.1415926535897932;
- const int N = 500005;
- int n;
- int t[4 * N];
- void build(int a[], int v, int tl, int tr)
- {
- if(tl == tr) t[v] = a[tl];
- else
- {
- int md = (tl + tr) / 2;
- build(a, v + v, tl, md);
- build(a, v + v + 1, md + 1, tr);
- t[v] = min(t[v + v], t[v + v + 1]);
- }
- }
- int query(int v, int tl, int tr, int l, int r)
- {
- if(l > r) return inf;
- if(l == tl && r == tr) return t[v];
- int tm = (tl + tr) / 2;
- return min(query(v + v, tl, tm, l, min(r,tm)), query(v + v + 1, tm + 1, tr, max(l,tm+1), r));
- }
- int qu(int l, int r)
- {
- return query(1, 0, n - 1, l, r);
- }
- int a[N];
- int b[5];
- int f(){
- int used[5];
- int ans = 0;
- memset(used, 0, sizeof(used));
- for(int i = 0; i < 3; ++i){
- used[b[i]] = 1;
- int ind1 = b[i] - 1;
- int ind2 = b[i] + 1;
- while(ind1 >= 0 && used[ind1] == 1){
- --ind1;
- }
- if(ind1 == -1) return 0;
- while(ind2 < 5 && used[ind2] == 1){
- ++ind2;
- }
- if(ind2 == 5) return 0;
- ans += min(a[ind1], a[ind2]);
- }
- return ans;
- }
- int main()
- {
- int mx = 0;
- ll sum = 0;
- //cin >> n;
- /*if(n <= 2){
- cout << 0 << endl;
- return 0;
- }
- if(n == 3){
- cout << min(a[0], a[2]) << endl;
- return 0;
- }*/
- int n = 5;
- for(int i = 1; i <= 5; ++i)
- {
- a[i - 1] = i;
- }
- do
- {
- int tmp = 0;
- for(int i = 1; i <= 5; ++i){
- b[i - 1] = i - 1;
- }
- do{
- tmp = max(tmp, f());
- }while(next_permutation(b, b + 5));
- //cout << 1 << endl;
- for(int i = 0; i < n; ++i)
- {
- //cin >> a[i];
- mx = max(a[i], mx);
- sum += a[i];
- }
- //if(a[0] == mx || a[1] == mx || a[n - 2] == mx || a[n - 1] == mx) while(true);
- ll ans = 0;
- for(int i = 2; i < n - 2; ++i)
- {
- if(a[i] == mx)
- {
- ll cur = sum - a[i - 1] - a[i + 1];
- cur -= mx;
- cur += min(a[0], a[n - 1]);
- ans = max(ans, cur);
- }
- }
- if(a[1] == mx)
- {
- ll cur = sum - a[2] - a[1] - a[0];
- cur += min(a[0], a[n - 1]);
- ans = max(ans, cur);
- }
- if(a[n - 2] == mx)
- {
- ll cur = sum - a[n - 1] - a[n - 2] - a[n - 3];
- cur += min(a[0], a[n - 1]);
- ans = max(ans, cur);
- }
- if(a[0] == mx)
- {
- ll cur = sum - a[0] - a[1];
- ans = max(ans, cur);
- }
- if(a[n - 1] == mx)
- {
- ll cur = sum - a[n - 1] - a[n - 2];
- ans = max(ans, cur);
- }
- //cout << ans << endl;
- if(ans != tmp){
- cout << ans << " " << tmp << endl;
- cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << endl;
- }
- }
- while(next_permutation(a, a + 5));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment