Submission #3990990


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }

typedef long long ll;
using namespace std;

int main() {
    
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n, 0);
    REP(i, n) cin >> a[i];
    vector<ll> X(q, 0);
    REP(j, q) cin >> X[j];

    vector<ll> imosX(q+1, 0);
    REP(j, q) imosX[j+1] = imosX[j] + X[j];

    REP(j, q) {
        ll x = X[j];
        ll ans = 0;
        vector<int> taken(n, 0); // 0: free, 1: takahashi, 2: aoki
        // int near = lower_bound(ALL_OF(a), x) - a.begin();
        // if (near > 0) if (x - a[near] > a[near - 1] - x) near--;
        for (int rem = n, turn = 0; rem--; turn++) {
            int chosen = -1;
            if (turn % 2 == 0) {
                for (int i = n; i--;) {
                    if (!taken[i]) {
                        chosen = i;
                        break;
                    }
                }
                ans += a[chosen];
            } else {
                ll mind = 0x7FFFFFFFFFFFFFFF;
                REP(i, n) {
                    if (!taken[i]) {
                        if (mind > abs(x - a[i])) {
                            mind = abs(x - a[i]);
                            chosen = i;
                        } else if (chosen >= 0) {
                            break;
                        }
                    }
                }
            }
            taken[chosen] = true;
        }
        cout << ans << endl;
    }
    
}

Submission Info

Submission Time
Task D - Nearest Card Game
User ganmodokix
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1912 Byte
Status TLE
Exec Time 2103 ms
Memory 3072 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 4
TLE × 22
Set Name Test Cases
Sample sample-01.txt, sample-02.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01.txt TLE 2103 ms 256 KB
02.txt TLE 2103 ms 256 KB
03.txt TLE 2103 ms 256 KB
04.txt TLE 2103 ms 384 KB
05.txt TLE 2103 ms 256 KB
06.txt AC 5 ms 256 KB
07.txt AC 205 ms 2816 KB
08.txt TLE 2103 ms 2944 KB
09.txt TLE 2103 ms 1792 KB
10.txt TLE 2103 ms 1792 KB
11.txt TLE 2103 ms 2944 KB
12.txt TLE 2103 ms 2944 KB
13.txt TLE 2103 ms 2944 KB
14.txt TLE 2103 ms 2944 KB
15.txt TLE 2103 ms 2944 KB
16.txt TLE 2103 ms 3072 KB
17.txt TLE 2103 ms 2944 KB
18.txt TLE 2103 ms 2944 KB
19.txt TLE 2103 ms 2944 KB
20.txt TLE 2103 ms 2944 KB
21.txt TLE 2103 ms 2944 KB
22.txt TLE 2103 ms 2944 KB
23.txt TLE 2103 ms 2944 KB
24.txt TLE 2103 ms 2944 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB