Submission #1301776


Source Code Expand

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

int main(){
	using ll = long long;
	ll n;
	cin >> n;
	priority_queue<ll, vector<ll>, greater<ll>> left;
	priority_queue<ll> right;
	ll left_sum = 0, right_sum = 0, mid[n];
	for(int i = 0; i < n; i++){
		ll a;
		cin >> a;
		left.push(a);
		left_sum += a;
	}
	for(int i = 0; i < n; i++) cin >> mid[i];
	for(int i = 0; i < n; i++){
		ll a;
		cin >> a;
		right.push(a);
		right_sum += a;
	}
	ll left_arr[n + 1], right_arr[n + 1];
	left_arr[0] = left_sum;
	right_arr[0] = right_sum;
	for(int i = 1; i < n + 1; i++){
		left.push(mid[i - 1]);
		left_sum += mid[i - 1];
		left_sum -= left.top();
		left.pop();
		left_arr[i] = left_sum;
	}
	for(int i = 1; i < n + 1; i++){
		right.push(mid[n - i]);
		right_sum += mid[n - i];
		right_sum -= right.top();
		right.pop();
		right_arr[i] = right_sum;
	}
	ll ans = -(1ll << 60);
	for(int i = 0; i < n + 1; i++) ans = max(ans, left_arr[i] - right_arr[n - i]);
	cout << ans << endl;
}

Submission Info

Submission Time
Task D - 3N Numbers
User jbyxm
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1040 Byte
Status
Exec Time 145 ms
Memory 4340 KB

Test Cases

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 56 ms 4340 KB
2_01.txt 137 ms 4340 KB
2_02.txt 120 ms 4340 KB
2_03.txt 111 ms 4340 KB
2_04.txt 112 ms 4340 KB
2_05.txt 111 ms 4340 KB
2_06.txt 111 ms 4340 KB
2_07.txt 112 ms 4340 KB
2_08.txt 62 ms 4212 KB
2_09.txt 61 ms 4212 KB
2_10.txt 62 ms 4212 KB
2_11.txt 61 ms 4212 KB
2_12.txt 144 ms 4212 KB
2_13.txt 145 ms 4340 KB
2_14.txt 145 ms 4212 KB
2_15.txt 145 ms 4212 KB