Submission #1518615
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define maxn 300002 #define FOR(i, l, r) for (int i=l; i<=r; ++i) #define FORD(i, r, l) for (int i=r; i>=l; --i) #define REP(i, r) for (int i=0; i<(int)r; ++i) #define REPD(i, r) for (int i=(int)r-1; i>=0; --i) #define fi first #define se second #define mk make_pair #define nil NULL #define y0 __y0 #define y1 __y1 #define x0 __x0 #define x1 __x1 #define next __next #define sz size #define Debug(X) {cerr << #X << " = " << X << '\n';} #define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';} #define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';} typedef long long ll; typedef double db; typedef pair<db, db> dd; typedef pair<int, int> ii; typedef vector<int> vi; const ll inf = 1e18; template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;} template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));} template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));} template<class T> T sqr(T a) {return a*a;} int n, a[maxn]; ll ps[maxn], Left[maxn], Right[maxn]; priority_queue<int, vector<int>, greater<int> > pq; int main() { //freopen("num3N.inp", "r", stdin); //freopen(".out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cin >> n; FOR(i, 1, 3*n) cin >> a[i]; ll s = 0; FOR(i, 1, 3*n) { if (int(pq.sz())<n) { s += a[i]; pq.push(a[i]); } else if (pq.top()<a[i]) { s -= pq.top(); pq.pop(); s += a[i]; pq.push(a[i]); } Left[i] = s; } s = 0; while (pq.sz()) pq.pop(); FORD(i, 3*n, 1) { if (int(pq.sz())<n) { s -= a[i]; pq.push(-a[i]); } else if (pq.top()<-a[i]) { s -= pq.top(); pq.pop(); s -= a[i]; pq.push(-a[i]); } Right[i] = s; } ll res = -inf; FOR(i, n, 2*n) { res = max(res, Left[i] + Right[i+1]); } cout << res; }
Submission Info
Submission Time | |
---|---|
Task | D - 3N Numbers |
User | phong22kk11 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 2100 Byte |
Status | AC |
Exec Time | 71 ms |
Memory | 8952 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 200 / 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 | 2 ms | 4352 KB |
0_01.txt | AC | 2 ms | 4352 KB |
0_02.txt | AC | 2 ms | 4352 KB |
1_00.txt | AC | 2 ms | 4352 KB |
1_01.txt | AC | 2 ms | 4352 KB |
1_02.txt | AC | 1 ms | 4352 KB |
1_03.txt | AC | 2 ms | 4352 KB |
1_04.txt | AC | 2 ms | 4352 KB |
1_05.txt | AC | 2 ms | 4352 KB |
1_06.txt | AC | 2 ms | 4352 KB |
1_07.txt | AC | 1 ms | 4352 KB |
1_08.txt | AC | 2 ms | 4352 KB |
1_09.txt | AC | 2 ms | 4352 KB |
1_10.txt | AC | 2 ms | 4352 KB |
1_11.txt | AC | 2 ms | 4352 KB |
1_12.txt | AC | 2 ms | 4352 KB |
1_13.txt | AC | 2 ms | 4352 KB |
1_14.txt | AC | 2 ms | 4352 KB |
1_15.txt | AC | 2 ms | 4352 KB |
1_16.txt | AC | 2 ms | 4352 KB |
1_17.txt | AC | 2 ms | 4352 KB |
1_18.txt | AC | 2 ms | 4352 KB |
1_19.txt | AC | 2 ms | 4352 KB |
1_20.txt | AC | 2 ms | 4352 KB |
1_21.txt | AC | 2 ms | 4352 KB |
1_22.txt | AC | 2 ms | 4352 KB |
1_23.txt | AC | 2 ms | 4352 KB |
2_00.txt | AC | 23 ms | 8952 KB |
2_01.txt | AC | 37 ms | 8952 KB |
2_02.txt | AC | 53 ms | 8952 KB |
2_03.txt | AC | 43 ms | 8952 KB |
2_04.txt | AC | 43 ms | 8952 KB |
2_05.txt | AC | 37 ms | 8952 KB |
2_06.txt | AC | 37 ms | 8952 KB |
2_07.txt | AC | 32 ms | 8952 KB |
2_08.txt | AC | 30 ms | 8952 KB |
2_09.txt | AC | 30 ms | 8952 KB |
2_10.txt | AC | 30 ms | 8952 KB |
2_11.txt | AC | 30 ms | 8952 KB |
2_12.txt | AC | 70 ms | 8952 KB |
2_13.txt | AC | 71 ms | 8952 KB |
2_14.txt | AC | 71 ms | 8952 KB |
2_15.txt | AC | 71 ms | 8952 KB |