Submission #1244437

#TimeUsernameProblemLanguageResultExecution timeMemory
1244437im2xtremeNile (IOI24_nile)C++20
0 / 100
50 ms6560 KiB
#include "nile.h" #include <bits/stdc++.h> using namespace std; struct Artifact { int id; int weight; int cost_alone; int cost_pair; int savings; }; vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) { int N = W.size(); int Q = E.size(); vector<Artifact> artifacts(N); for (int i = 0; i < N; ++i) { artifacts[i] = {i, W[i], A[i], B[i], A[i] - B[i]}; } vector<long long> R(Q); for (int q = 0; q < Q; ++q) { int D = E[q]; vector<Artifact> sorted = artifacts; sort(sorted.begin(), sorted.end(), [](const Artifact &a, const Artifact &b) { return a.weight < b.weight; }); vector<bool> used(N, false); long long total_cost = 0; int l = 0, r = N - 1; while (l < r) { if (used[l]) { l++; continue; } if (used[r]) { r--; continue; } if (sorted[r].weight - sorted[l].weight > D) { r--; continue; } if (sorted[l].savings + sorted[r].savings >= 0) { total_cost += sorted[l].cost_pair + sorted[r].cost_pair; used[l] = used[r] = true; l++; r--; } else { total_cost += sorted[l].cost_alone; used[l] = true; l++; } } for (int i = 0; i < N; ++i) { if (!used[i]) { total_cost += sorted[i].cost_alone; } } R[q] = total_cost; } return R; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...