Submission #1691788
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=-LINF,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); } FOR(idx,n,2*n+1) { if(lflg) { l-=lx,lflg=false,l+=a[idx-1],lx=a[idx-1]; } if(rflg) { r+=ma[n-1].first,rflg=false; } ans=max(ans,l-r); auto tmp=find(ALL(rx),idx); if(tmp!=rx.end()) { r-=a[idx],rflg=true; rx.erase(tmp); } if(a[idx]>lx) lflg=true; auto itr=find(ALL(ma),P(a[idx],idx)); ma.erase(itr); } cout<<ans<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 3N Numbers |
User | moko_freedom |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1147 Byte |
Status | WA |
Exec Time | 2112 ms |
Memory | 9068 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | 0 / 200 | ||||||||||||
Status |
|
|
|
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 | 3 ms | 384 KB |
1_09.txt | AC | 3 ms | 384 KB |
1_10.txt | AC | 3 ms | 384 KB |
1_11.txt | WA | 3 ms | 384 KB |
1_12.txt | AC | 3 ms | 384 KB |
1_13.txt | WA | 3 ms | 384 KB |
1_14.txt | AC | 3 ms | 384 KB |
1_15.txt | AC | 3 ms | 384 KB |
1_16.txt | WA | 3 ms | 384 KB |
1_17.txt | WA | 3 ms | 384 KB |
1_18.txt | WA | 3 ms | 384 KB |
1_19.txt | WA | 3 ms | 384 KB |
1_20.txt | WA | 3 ms | 384 KB |
1_21.txt | WA | 3 ms | 384 KB |
1_22.txt | WA | 3 ms | 384 KB |
1_23.txt | WA | 3 ms | 384 KB |
2_00.txt | TLE | 2104 ms | 8940 KB |
2_01.txt | TLE | 2104 ms | 8684 KB |
2_02.txt | TLE | 2104 ms | 8684 KB |
2_03.txt | TLE | 2104 ms | 8300 KB |
2_04.txt | TLE | 2104 ms | 8812 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 | 8172 KB |
2_09.txt | TLE | 2104 ms | 9068 KB |
2_10.txt | TLE | 2104 ms | 8300 KB |
2_11.txt | TLE | 2112 ms | 8812 KB |
2_12.txt | TLE | 2104 ms | 8940 KB |
2_13.txt | TLE | 2104 ms | 9068 KB |
2_14.txt | TLE | 2104 ms | 8300 KB |
2_15.txt | TLE | 2104 ms | 8300 KB |