CSES - COCI 2007/2008 #1 - Results
Submission details
Task:Prinova
Sender:henrikaalto
Submission time:2019-07-29 15:44:02 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.01 sdetails
#9ACCEPTED0.01 sdetails
#10ACCEPTED0.01 sdetails

Code

#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
using ii=long long;
const ii inf = 1e9;
int main()
{
    ii n;
    cin >> n;
    vector<ii> v(n + 2);
    v[0] = -inf;
    for (ii i = 0; i < n; ++i) {
        cin >> v[i + 1];
    }
    v.back() = inf;
    sort(all(v));
    ii a, b;
    cin >> a >> b;
    pair<ii, ii> res;
    for (ii i = 1; i <= n + 1; ++i) {
        ii loc = max(a, (v[i] + v[i - 1]) / 2);
        loc = min(loc, b);
        assert(a <= loc);
        assert(loc <= b);
        for (ii j = -5; j <= 5; ++j) {
            loc += j;
            if (loc & 1 && a <= loc && loc <= b) {
                res = max(res, make_pair(min(loc - v[i - 1], v[i] - loc), loc));
            }
            loc -= j;
        }
    }
    cout << res.second << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
5
38 50 60 30 48
23 69

correct output
69

user output
69

Test 2

Verdict: ACCEPTED

input
5
12 10 50 24 40
9 16

correct output
15

user output
15

Test 3

Verdict: ACCEPTED

input
10
46 64 26 82 18 106 60 138 194 ...

correct output
165

user output
167

Test 4

Verdict: ACCEPTED

input
20
114 48 86 180 176 66 126 194 5...

correct output
99

user output
101

Test 5

Verdict: ACCEPTED

input
30
46 112 106 70 186 80 62 2 162 ...

correct output
25

user output
123

Test 6

Verdict: ACCEPTED

input
50
7362 772 4354 5462 4924 5224 2...

correct output
3953

user output
3953

Test 7

Verdict: ACCEPTED

input
67
7518 4798 5528 3806 7798 3396 ...

correct output
6467

user output
6467

Test 8

Verdict: ACCEPTED

input
79
263044060 323471968 60083128 7...

correct output
173959055

user output
173959057

Test 9

Verdict: ACCEPTED

input
99
412812216 39588698 618476302 2...

correct output
2577535

user output
2577535

Test 10

Verdict: ACCEPTED

input
100
635179944 592614358 645156538 ...

correct output
493216533

user output
493216533