이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pi = pair<ll, pair<ll, ll>>;
using ii = pair<ll, ll>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
ll min_total_length(vector<int> R, vector<int> B) {
ll N = R.size(), M = B.size(), res = 0;
vector<pair<ll, ll>> arr(N + M);
for(ll l = 0; l < N; l++) arr[l] = {R[l], 1};
for(ll l = 0; l < M; l++) arr[l + N] = {B[l], 0};
sort(arr.begin(), arr.end()); vector<bool> vis(N, 0);
for(ll l = N - 1, i = 0; l >= 0 && i < M; l--, i++) {
res += arr[N + i].ff - arr[l].ff; vis[l] = 1;
}
for(ll l = 2 * N; l < N + M; l++)
res += arr[l].ff - arr[N - 1].ff;
for(ll l = 0; l < N; l++) {
if(vis[l]) break;
res += arr[N].ff - arr[l].ff;
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |