Submission #374895

#TimeUsernameProblemLanguageResultExecution timeMemory
374895peijarJust Long Neckties (JOI20_ho_t1)C++17
9 / 100
86 ms12140 KiB
#include <bits/stdc++.h> #define int long long using namespace std; /* * Si prend plus petit : cout = 0 * sinon cout > 0 * Si N de chaque côté : * a_1 <= ... <= a_n * b_1 <= ... <= b_n * Si b_1 <= a_1 : mieux de mettre avec a_1 * Sinon b_1 > a_1 : * SI on met a_1 avec b_i, i > 1 et b_1 avec j, j > 1 * cout : max(bi - a1, max(b1 - aj, 0)) * S max(bi-aj, 0) = 0 : mieux echanger * Tri par ordre croissant ! */ const int nbFeuilles = 1 << 17; int curCost[2 * nbFeuilles]; void maj(int pos, int val) { pos += nbFeuilles; curCost[pos] = val; while (pos > 1) { pos /= 2; curCost[pos] = max(curCost[2*pos], curCost[2*pos+1]); } } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; vector<pair<int, int>> A(N+1); vector<int> B(N); for (int i(0); i <= N; ++i) { cin >> A[i].first; A[i].second = i; } for (auto &v : B) cin >> v; sort(A.begin(), A.end()); sort(B.begin(), B.end()); for (int i(0); i < N; ++i) curCost[i + nbFeuilles] = A[i+1].first - B[i]; for (int i(nbFeuilles-1); i >= 1; --i) curCost[i] = max(curCost[2*i], curCost[2*i+1]); vector<int> sol(N+1); sol[A[0].second] = max(0LL, curCost[1]); for (int i(0); i < N; ++i) { maj(i, A[i].first - B[i]); sol[A[i+1].second] = max(0LL, curCost[1]); } for (auto v: sol) cout << v<< ' '; cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...