/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 444.0 KiB
#5 Wrong Answer 14ms 532.0 KiB
#6 Wrong Answer 10ms 580.0 KiB

Code

#if __has_include("../stdc++.h")
	#include "../stdc++.h"
#else
	#include <bits/stdc++.h>
#endif

template <typename T>
std::istream &operator>>(std::istream &in, std::vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v)
{
    for (std::size_t i = 0; i < v.size(); ++i)
        out << v[i] << (i + 1 == v.size() ? "" : " ");
    return out;
}

inline void yes() { std::cout << "Yes\n"; }
inline void no()  { std::cout << "No\n";  }

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    cin >> a;
    sort(a.begin(), a.end(), greater<long long>());
    long long curr = 0;
    curr += a[0];
    curr -= a[1];
    long long bestR = curr;
    if (n == 2) {
        cout << curr << '\n';
        return;
    }
    for (int i = 2; i < n; i++) {
        if (i % 2 == 0) {
            // cerr << "bestR: " << bestR << '\n';
            if (curr + a[i] > bestR) {
                curr += a[i];
            }
        } else {
            if (curr - a[i] <= bestR) {
                curr -= a[i];
            }
            else {
                break;
            }
        }
    }
    curr = min(a[0] - a[1] + a[2], curr);
    cout << max(curr, bestR) << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1208 C. Game on Integer
Contest
Educational Round 1
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 17:24:00
Judged At
2025-07-14 17:24:00
Judged By
Score
5
Total Time
14ms
Peak Memory
580.0 KiB