Submission #541984

# Submission time Handle Problem Language Result Execution time Memory
541984 2022-03-25T00:31:36 Z Olympia Akcija (COCI15_akcija) C++17
80 / 80
16 ms 1660 KB
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <limits.h>
#include <queue>

using namespace std;
int main() {
    //freopen("inp.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<int> v(N); for (int i = 0; i < N; i++) cin >> v[i];
    sort(v.begin(), v.end());
    deque<int> d;
    for (int i: v) {
        d.push_back(i);
    }
    int64_t ans = 0;
    while (!d.empty()) {
        if (d.size() <= 2) {
            while (!d.empty()) {
                ans += d.back(), d.pop_back();
            }
            break;
        }
        ans += d.back();
        //cout << "GET " << d.back() << '\n';
        d.pop_back();
        ans += d.back();
        //cout << "GET " << d.back() << '\n';
        d.pop_back();
        d.pop_back();
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 11 ms 1484 KB Output is correct
7 Correct 8 ms 1492 KB Output is correct
8 Correct 9 ms 1492 KB Output is correct
9 Correct 16 ms 1656 KB Output is correct
10 Correct 16 ms 1660 KB Output is correct