Submission #1518151
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; const ll INF = 1000000000000000000ll; const ll MOD = 1000000007ll; const double EPS = 1e-8; int main(void) { //ios_base::sync_with_stdio(false); //cin.tie(0); int n; cin >> n; priority_queue<int, vector<int>, greater<int> > a; deque<int> b; priority_queue<int> c; for(int i=0; i<n; i++){ int t; cin >> t; a.push(t); } for(int i=0; i<n; i++){ int t; cin >> t; b.pb(t); } for(int i=0; i<n; i++){ int t; cin >> t; c.push(t); } for(int i=0; i<n; i++){ int as = -a.top() + b.front(); int cs = c.top() - b.back(); if(as < 0 && cs < 0){ if(b.size() == 1){ b.pop_front(); continue; } int j=1; while(-a.top() + b[j] == c.top() - b[b.size()-1-j]){ j++; if(j >= b.size()){ b.pop_front(); break; } if(-a.top() + b[j] > c.top() - b[b.size()-1-j]){ b.pop_front(); break; }else if(-a.top() + b[j] < c.top() - b[b.size()-1-j]){ b.pop_back(); break; } } }else if(as >= cs){ a.pop(); a.push(b.front()); b.pop_front(); }else{ c.pop(); c.push(b.back()); b.pop_back(); } /* cout << a.size() << endl; cout << c.size() << endl; for(int i=0; i<n; i++){ printf("%d ", b[i]); } puts(""); */ } ll ans = 0; for(int i=0; i<n; i++){ ans += a.top(); //printf("%d\n", a.top()); a.pop(); } for(int i=0; i<n; i++){ ans -= c.top(); //printf("%d\n", c.top()); c.pop(); } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 3N Numbers |
User | tanutarou |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1652 Byte |
Status | WA |
Exec Time | 141 ms |
Memory | 1784 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 | 2 ms | 256 KB |
1_09.txt | AC | 2 ms | 256 KB |
1_10.txt | AC | 2 ms | 256 KB |
1_11.txt | AC | 2 ms | 256 KB |
1_12.txt | AC | 2 ms | 256 KB |
1_13.txt | AC | 2 ms | 256 KB |
1_14.txt | AC | 2 ms | 256 KB |
1_15.txt | AC | 2 ms | 256 KB |
1_16.txt | WA | 2 ms | 256 KB |
1_17.txt | WA | 2 ms | 256 KB |
1_18.txt | WA | 2 ms | 256 KB |
1_19.txt | WA | 2 ms | 256 KB |
1_20.txt | WA | 2 ms | 256 KB |
1_21.txt | WA | 2 ms | 256 KB |
1_22.txt | WA | 2 ms | 256 KB |
1_23.txt | WA | 2 ms | 256 KB |
2_00.txt | AC | 57 ms | 1784 KB |
2_01.txt | AC | 137 ms | 1784 KB |
2_02.txt | AC | 110 ms | 1784 KB |
2_03.txt | AC | 109 ms | 1784 KB |
2_04.txt | AC | 110 ms | 1784 KB |
2_05.txt | AC | 109 ms | 1784 KB |
2_06.txt | AC | 109 ms | 1784 KB |
2_07.txt | AC | 105 ms | 1784 KB |
2_08.txt | WA | 61 ms | 1784 KB |
2_09.txt | WA | 60 ms | 1784 KB |
2_10.txt | WA | 61 ms | 1784 KB |
2_11.txt | WA | 60 ms | 1784 KB |
2_12.txt | WA | 139 ms | 1784 KB |
2_13.txt | WA | 141 ms | 1784 KB |
2_14.txt | WA | 141 ms | 1784 KB |
2_15.txt | WA | 141 ms | 1784 KB |