Submission #1225014

#TimeUsernameProblemLanguageResultExecution timeMemory
1225014crazy0215Hacker (BOI15_hac)C++20
0 / 100
0 ms328 KiB
//毁灭吧
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define show(x) cout << #x << " " << x << "\n";
#define showds(x) cout << #x << " "; for(auto y : x) cout << y << " "; cout << "\n";
typedef pair<int, int> ii;

bool cmp(pair<int, ii> a, pair<int, ii> b) {
	//if (a.fi==b.fi) return a.se<b.se;
	return a.fi>b.fi;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int a[n+n/2-1], ans=0, m=0;
    pair<int, ii> b[n];
    for (int i=0; i<n; i++) {
		cin >> a[i];
		ans+=a[i];
		if (i<n/2) m+=a[i];
	}
	b[0].fi=m, b[0].se.fi=0, b[0].se.se=n/2-1;
	for (int i=n; i<n+n/2-1; i++) a[i]=a[i%n];
    //showds(a)
	for (int i=n/2, j=0; j<n-1; i++, j++) {
        m+=-a[j]+a[i], b[j+1].fi=m, b[j+1].se.fi=j+1, b[j+1].se.se=i%n;
        //show(j+1)
    }
	//for (auto i:b) cout << i.fi << ' ';
    sort(b, b+n, cmp);
    ////<<3;
	set<int> c;
	if (b[0].se.fi<=b[0].se.se) for (int i=b[0].se.fi; i<=b[0].se.se; i++) c.insert(i);
    else {
        for (int i=0; i<=b[0].se.se; i++) c.insert(i);
        for (int i=b[0].se.fi; i<n; i++) c.insert(i);
    }
    //showds(c)
    int ct=n/2;
	for (int i=1; i<n; i++) {
        //show(ct)
        if (b[0].se.fi<=b[0].se.se) {
            if (b[i].se.fi<=b[i].se.se) {
                if (b[0].se.fi<b[i].se.fi) ct-=b[i].se.fi-b[0].se.fi, b[0].se.fi=b[i].se.fi;
                if (b[0].se.se>b[i].se.se) ct-=b[0].se.se-b[i].se.se, b[0].se.se=b[i].se.se;
            } else {
                if (b[i].se.fi>b[0].se.se) ct=b[i].se.se-b[0].se.fi+1, b[0].se.se=b[i].se.se;
                else ct=b[0].se.se-b[i].se.fi+1, b[0].se.fi=b[i].se.fi;
            }
        } else {
            if (b[i].se.se<=b[i].se.fi) {
                if (b[0].se.fi<b[i].se.fi) ct-=b[i].se.fi-b[0].se.fi, b[0].se.fi=b[i].se.fi;
                if (b[0].se.se>b[i].se.se) ct-=b[0].se.se-b[i].se.se, b[0].se.se=b[i].se.se;
            } else {
                //show(ct)
                //show(b[0].se.fi) show(b[0].se.se) show(b[i].se.fi) show(b[i].se.se)
                if (b[i].se.fi>b[0].se.se) ct=b[i].se.se-b[0].se.fi+1, b[0].se.se=b[i].se.se;
                else ct=b[0].se.se-b[i].se.fi+1, b[0].se.fi=b[i].se.fi;
                //show(ct)
                //show(b[0].se.fi) show(b[0].se.se) show(b[i].se.fi) show(b[i].se.se)
            }
        }
        /*if (b[0].se.fi<b[i].se.fi) {
            ct-=b[i].se.fi-b[0].se.fi, b[0].se.fi=b[i].se.fi;
            show(ct)
        }
        //show(ct)
        if (b[0].se.se>b[i].se.se) {
            ct-=b[0].se.se-b[i].se.se, b[0].se.se=b[i].se.se;
            show(ct)
        }*/
        //show(ct)
        //show(b[0].se.fi) show(b[0].se.se)
        if (ct<=0) {
            cout << ans-b[i].fi;
            break;
        }
	}
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...