Submission #1104423

#TimeUsernameProblemLanguageResultExecution timeMemory
1104423qrnAkcija (COCI15_akcija)C++14
16 / 80
13 ms2384 KiB
#include <bits/stdc++.h> using namespace std; template<class ISqr, class T> ISqr& operator>>(ISqr& is, vector<T>& v) { for (auto& x : v) is >> x; return is; } #define SPEED \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); template <typename T> void show(vector<T> &v) { for (T i : v) { cout << i << ' '; } cout << endl; } #define pb push_back #define ins insert #define fi first #define se second #define endl "\n" #define ALL(x) x.begin(), x.end() #define sz(x) x.size() #define int long long #define _ << " " << #define no cout << "No" << endl; #define yes cout << "Yes" << endl; #define impos cout << -1 << endl; #define vi vector<int> #define pii pair<int,int> #define vpii vector<pii> void solve() { // 4 5 5 5 5 6 6 // 1 2 3 4 5 6 7 8 9 10 int n; cin >> n; vi a(n); cin >> a; int ans = 0; sort(ALL(a)); int l = 1, r = n - 1; vi handled(n+1, 0); while(l < r) { ans += (a[l] + a[r]); handled[l] = 1; handled[r] = 1; handled[l-1] = 1; if(l - 2 >= 0) handled[l-2] = 1; l += 2; r--; } vi rem; for(int i = 0; i < n; i++) { if(handled[i] == 0) { rem.pb(a[i]); } } if(sz(rem) == 1) { cout << ans + rem[0] << endl; } else if(sz(rem) == 2) { cout << ans + rem[1] + rem[0] << endl; } else { cout << ans << endl; } } signed main(){ SPEED; int t = 1; // cin >> t; for(int cs = 1; cs <= t; cs++) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...