답안 #1104423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104423 2024-10-23T17:45:50 Z qrn Akcija (COCI15_akcija) C++14
16 / 80
13 ms 2384 KB
#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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Incorrect 1 ms 508 KB Output isn't correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Incorrect 1 ms 504 KB Output isn't correct
6 Incorrect 11 ms 2380 KB Output isn't correct
7 Correct 7 ms 2384 KB Output is correct
8 Correct 7 ms 2216 KB Output is correct
9 Incorrect 13 ms 2384 KB Output isn't correct
10 Incorrect 13 ms 2384 KB Output isn't correct