Submission #2854260


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    long n;
    // vector<int> x;
    cin >> n;

    vector<long> a;
    // long a[n];
    long tmp;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        a.push_back(tmp);
    };
    sort(a.begin(), a.end());
    long max_val = a[n - 1];
    decltype(a)::iterator large_med;
    decltype(a)::iterator small_med;
    decltype(a)::iterator nearest_med;
    auto true_med = static_cast<long>(round(max_val / 2.0));
    large_med  = lower_bound(a.begin(), a.end(), true_med);

    long large_pos = 0;
    for (auto &num : a) {
        if (num == *large_med) break;
        large_pos++;
    }
    // long small_pos = 0;
    // if (large_pos > 0) {
    //     small_pos = large_pos - 1;
    // } else {
    //     small_pos = large_pos;
    // }

    long med_val;
    if (large_pos == n - 1) {
        med_val = a[large_pos - 1];
    } else if (large_pos == 0) {
        med_val = a[large_pos];
    } else if (a[large_pos] - true_med > true_med - a[large_pos - 1]) {
        med_val = a[large_pos - 1];
    } else {
        med_val = a[large_pos];
    }
    cout  << max_val << ' ' << med_val << "\n";

    return 0;
}

Submission Info

Submission Time
Task D - Binomial Coefficients
User gaudi08
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1293 Byte
Status AC
Exec Time 18 ms
Memory 1400 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 17
Set Name Test Cases
Sample sample1.txt, sample2.txt
All even0.txt, even1.txt, float.txt, odd0.txt, odd1.txt, rnd_0.txt, rnd_1.txt, rnd_2.txt, rnd_3.txt, rnd_4.txt, rnd_5.txt, rnd_6.txt, rnd_7.txt, rnd_8.txt, rnd_9.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
even0.txt AC 17 ms 1400 KB
even1.txt AC 17 ms 1400 KB
float.txt AC 17 ms 1400 KB
odd0.txt AC 17 ms 1400 KB
odd1.txt AC 17 ms 1400 KB
rnd_0.txt AC 16 ms 1400 KB
rnd_1.txt AC 15 ms 1400 KB
rnd_2.txt AC 16 ms 1400 KB
rnd_3.txt AC 15 ms 1400 KB
rnd_4.txt AC 13 ms 1400 KB
rnd_5.txt AC 18 ms 1400 KB
rnd_6.txt AC 14 ms 1400 KB
rnd_7.txt AC 14 ms 1400 KB
rnd_8.txt AC 15 ms 1400 KB
rnd_9.txt AC 15 ms 1400 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB