Contest Duration: ~ (local time) (100 minutes) Back to Home

Submission #2093049

Source Code Expand

Copy
```#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;

int n;

vector<ll> a;

ll ldp[100010];
ll rdp[100010];

int main()
{
cin >> n;

a.resize(n * 3);

for(ll& x : a)
{
cin >> x;
}

//left
{
priority_queue<ll,vector<ll>,greater<ll>> left;
for(int i = 0;i < n;i++)
{
left.push(a[i]);
ldp[0] += a[i];
}

for(int i = 0;i < n;i++)
{
if(a[n + i] > left.top())
{
left.push(a[n + i]);
ldp[i + 1] = ldp[i] - left.top() + a[n + i];
left.pop();
}
else
{
ldp[i + 1] = ldp[i];
}
}
}

//right

{
priority_queue<ll> right;
for(int i = 0;i < n;i++)
{
right.push(a[2 * n + i]);
rdp[0] += a[2 * n + i];
}

for(int i = 0;i < n;i++)
{
int ind = 2 * n - 1 - i;
if(a[ind] < right.top())
{
right.push(a[ind]);
rdp[i + 1] = rdp[i] - right.top() + a[ind];
right.pop();
}
else
{
rdp[i + 1] = rdp[i];
}
}
}

ll result = -1 * (1LL<< 60);

for(int i = 0;i <= n;i++)
{
result = max(result , ldp[i] - rdp[n - i]);
}

cout << result << endl;
return 0;
}
```

#### Submission Info

Submission Time 2018-02-13 22:28:26+0900 D - 3N Numbers niuez C++14 (GCC 5.4.1) 500 1213 Byte AC 141 ms 5992 KB

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt
Subtask 300 / 300 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 200 / 200 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 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 1 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 1 ms 256 KB
1_06.txt 1 ms 256 KB
1_07.txt 1 ms 256 KB
1_08.txt 2 ms 256 KB
1_09.txt 3 ms 256 KB
1_10.txt 2 ms 256 KB
1_11.txt 2 ms 256 KB
1_12.txt 2 ms 256 KB
1_13.txt 2 ms 256 KB
1_14.txt 2 ms 256 KB
1_15.txt 2 ms 256 KB
1_16.txt 2 ms 256 KB
1_17.txt 2 ms 256 KB
1_18.txt 2 ms 256 KB
1_19.txt 2 ms 256 KB
1_20.txt 3 ms 256 KB
1_21.txt 3 ms 256 KB
1_22.txt 3 ms 256 KB
1_23.txt 3 ms 256 KB
2_00.txt 50 ms 5988 KB
2_01.txt 131 ms 5988 KB
2_02.txt 111 ms 5988 KB
2_03.txt 106 ms 5988 KB
2_04.txt 106 ms 5988 KB
2_05.txt 107 ms 5988 KB
2_06.txt 106 ms 5988 KB
2_07.txt 101 ms 5988 KB
2_08.txt 56 ms 5872 KB
2_09.txt 56 ms 5876 KB
2_10.txt 58 ms 5868 KB
2_11.txt 58 ms 5876 KB
2_12.txt 140 ms 5872 KB
2_13.txt 141 ms 5988 KB
2_14.txt 141 ms 5992 KB
2_15.txt 141 ms 5992 KB