# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1104423 | qrn | Akcija (COCI15_akcija) | C++14 | 13 ms | 2384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |