Submission #1691834


Source Code Expand

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;

#define INF 2147483647
#define LINF 9223372036854775807
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<ll, int> P;

int n;
ll a[3*100000];
vector<ll> mi;
vector<P> ma;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>n;
	REP(i,3*n) {
		cin>>a[i];
		if(i<n) mi.push_back(a[i]);
		else ma.push_back(P(a[i],i));
	}
	sort(ALL(ma)); sort(mi.rbegin(),mi.rend());

	ll ans,l=0,r=0;
	ll lx=mi[n-1];
	vector<ll> rx;
	bool lflg=false,rflg=false;

	REP(i,n) l+=mi[i];
	REP(i,n) {
		r+=ma[i].first;
		rx.push_back(ma[i].second);
	}
	ans=l-r;

	FOR(idx,n,2*n) {
		auto itr=find(ALL(ma),P(a[idx],idx));
		ma.erase(itr);
		mi.push_back(a[idx]);
		sort(mi.rbegin(),mi.rend());

		auto tmp=find(ALL(rx),idx);
		if(tmp!=rx.end()) {
			r-=a[idx],r+=ma[n-1].first;
			rx.erase(tmp);
			rx.push_back(ma[n-1].second);
		}

		if(a[idx]>lx)	l-=lx,l+=a[idx],lx=mi[n-1];
		ans=max(ans,l-r);

	}
	cout<<ans<<endl;

	return 0;
}

Submission Info

Submission Time
Task D - 3N Numbers
User moko_freedom
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1150 Byte
Status TLE
Exec Time 2104 ms
Memory 9196 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 300 / 300 0 / 200
Status
AC × 3
AC × 27
AC × 27
TLE × 16
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
Subtask 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 1 ms 256 KB
1_08.txt AC 15 ms 384 KB
1_09.txt AC 15 ms 384 KB
1_10.txt AC 14 ms 384 KB
1_11.txt AC 14 ms 384 KB
1_12.txt AC 14 ms 384 KB
1_13.txt AC 14 ms 384 KB
1_14.txt AC 14 ms 384 KB
1_15.txt AC 14 ms 384 KB
1_16.txt AC 15 ms 384 KB
1_17.txt AC 15 ms 384 KB
1_18.txt AC 15 ms 384 KB
1_19.txt AC 15 ms 384 KB
1_20.txt AC 17 ms 384 KB
1_21.txt AC 18 ms 384 KB
1_22.txt AC 18 ms 384 KB
1_23.txt AC 18 ms 384 KB
2_00.txt TLE 2104 ms 8300 KB
2_01.txt TLE 2104 ms 8300 KB
2_02.txt TLE 2104 ms 8812 KB
2_03.txt TLE 2104 ms 8940 KB
2_04.txt TLE 2104 ms 8556 KB
2_05.txt TLE 2104 ms 8300 KB
2_06.txt TLE 2104 ms 8300 KB
2_07.txt TLE 2104 ms 8300 KB
2_08.txt TLE 2104 ms 8300 KB
2_09.txt TLE 2104 ms 8172 KB
2_10.txt TLE 2104 ms 8684 KB
2_11.txt TLE 2104 ms 8172 KB
2_12.txt TLE 2104 ms 8300 KB
2_13.txt TLE 2104 ms 9196 KB
2_14.txt TLE 2104 ms 9196 KB
2_15.txt TLE 2104 ms 8300 KB