Pagini recente »
Istoria paginii runda/test_interesant/clasament
|
Clasament lasm_21_12_2022_clasa11
|
Cod sursă (job #465401)
|
2013-04-25-test-6-7-8
|
Cod sursă (job #803120)
Cod sursă (job
#803120)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
freopen("lanterna.in", "r", stdin);
freopen("lanterna.out", "w", stdout);
int N;
cin >> N;
vector<int> times(N);
for (int i = 0; i < N; i++) {
cin >> times[i];
}
// Sort the times in ascending order
sort(times.begin(), times.end());
int total_time = 0;
while (N > 3) {
// Two strategies:
// 1. Send the two slowest across and return the fastest
int strategyA = times[1] + times[0] + times[N-1] + times[1];
// 2. Send the two fastest across and return the fastest
int strategyB = times[1] + times[0] + times[N-1] + times[2];
// Add the minimal of both strategies
total_time += min(strategyA, strategyB);
// Reduce the number of people by 2 since they are now across the bridge
N--;
}
// For the last three people
if (N == 3) {
total_time += times[2] + times[1];
}
cout << total_time << endl;
return 0;
}