Submission #3776315
Source Code Expand
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); } int lcm(int x, int y) { return x / gcd(x, y) * y; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> a(3 * n); for (int i = 0; i < 3 * n; i++) { cin >> a[i]; } vector<ll> front(3 * n + 1); { priority_queue<ll, vector<ll>, greater<ll>> que; for (int i = 0; i < 3 * n; i++) { que.push(a[i]); ll b = 0; if (que.size() == n + 1) { b = que.top(); que.pop(); } front[i + 1] = front[i] + a[i] - b; } } vector<ll> back(3 * n + 1); { priority_queue<ll> que; for (int i = 3 * n -1; i >= 0; i--) { que.push(a[i]); ll b = 0; if (que.size() == n + 1) { b = que.top(); que.pop(); } back[i] = back[i + 1] + a[i] - b; } } ll result = -INT64_MAX; for (int i = n; i <= 2 * n; i++) { result = max(result, front[i] - back[i]); } cout << result << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 3N Numbers |
User | ant2357 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1297 Byte |
Status | AC |
Exec Time | 78 ms |
Memory | 9068 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 | 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 | 2 ms | 384 KB |
1_09.txt | AC | 2 ms | 384 KB |
1_10.txt | AC | 2 ms | 384 KB |
1_11.txt | AC | 2 ms | 384 KB |
1_12.txt | AC | 2 ms | 384 KB |
1_13.txt | AC | 2 ms | 384 KB |
1_14.txt | AC | 2 ms | 384 KB |
1_15.txt | AC | 2 ms | 384 KB |
1_16.txt | AC | 2 ms | 384 KB |
1_17.txt | AC | 2 ms | 384 KB |
1_18.txt | AC | 2 ms | 384 KB |
1_19.txt | AC | 2 ms | 384 KB |
1_20.txt | AC | 2 ms | 384 KB |
1_21.txt | AC | 2 ms | 384 KB |
1_22.txt | AC | 2 ms | 384 KB |
1_23.txt | AC | 2 ms | 384 KB |
2_00.txt | AC | 36 ms | 9060 KB |
2_01.txt | AC | 50 ms | 9060 KB |
2_02.txt | AC | 52 ms | 9060 KB |
2_03.txt | AC | 54 ms | 9060 KB |
2_04.txt | AC | 53 ms | 9060 KB |
2_05.txt | AC | 54 ms | 9060 KB |
2_06.txt | AC | 54 ms | 9060 KB |
2_07.txt | AC | 55 ms | 9060 KB |
2_08.txt | AC | 46 ms | 8944 KB |
2_09.txt | AC | 46 ms | 8948 KB |
2_10.txt | AC | 45 ms | 9068 KB |
2_11.txt | AC | 45 ms | 8948 KB |
2_12.txt | AC | 76 ms | 8944 KB |
2_13.txt | AC | 78 ms | 9060 KB |
2_14.txt | AC | 77 ms | 9064 KB |
2_15.txt | AC | 77 ms | 9064 KB |