Submission #35485344


Source Code Expand

#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
//ここからメイン
int H, W;
vector<vector<char>> MAP;
vector<vector<bool>> res(16, vector<bool>(16));
int MAX = -1;

    
int main() {
    ll N;
    cin >> N;
    vector<ll>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    if (N == 2 && (A[0] + A[1]) % 2 == 1)cout << -1 << endl;
    else {
        vector <ll> odd, even;
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 1)odd.push_back(A[i]);
            else even.push_back(A[i]);

        }
        sort(odd.begin(), odd.end());
        sort(even.begin(), even.end());
        ll o_s = odd.size();
        ll e_s = even.size();
        ll OM, EM;
        if (o_s < 2) {
            OM = -1;
        }
        else {
            OM = odd[o_s - 1] + odd[o_s - 2];
        }
        if (e_s < 2) {
            EM = -1;
        }
        else {
            EM = even[e_s - 1] + even[e_s - 2];
        }
        cout << max(OM, EM) << endl;

    }
    return 0;
}

Submission Info

Submission Time
Task C - Max Even
User amaoto
Language C++ (GCC 9.2.1)
Score 300
Code Size 1138 Byte
Status AC
Exec Time 83 ms
Memory 7660 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 20
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 7 ms 3456 KiB
00_sample_02.txt AC 2 ms 3424 KiB
01_test_01.txt AC 2 ms 3344 KiB
01_test_02.txt AC 2 ms 3376 KiB
01_test_03.txt AC 83 ms 7660 KiB
01_test_04.txt AC 76 ms 6808 KiB
01_test_05.txt AC 77 ms 6744 KiB
01_test_06.txt AC 77 ms 6764 KiB
01_test_07.txt AC 79 ms 6752 KiB
01_test_08.txt AC 78 ms 6712 KiB
01_test_09.txt AC 79 ms 7020 KiB
01_test_10.txt AC 78 ms 6680 KiB
01_test_11.txt AC 77 ms 7076 KiB
01_test_12.txt AC 74 ms 6364 KiB
01_test_13.txt AC 75 ms 6844 KiB
02_handmade_01.txt AC 2 ms 3456 KiB
02_handmade_02.txt AC 2 ms 3456 KiB
02_handmade_03.txt AC 64 ms 6912 KiB
02_handmade_04.txt AC 2 ms 3556 KiB
02_handmade_05.txt AC 80 ms 6684 KiB