Submission #21610512


Source Code Expand

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 4e5 + 5;
int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < 2 * n; ++i) {
    scanf("%d", &a[i]);
  }
  return true;
}

priority_queue<int> pq;

void solve() {
  while (!pq.empty()) {
    pq.pop();
  }
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    pq.push(a[i]);
    pq.push(a[2 * n - 1 - i]);
    res += pq.top();
    pq.pop();
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Submission Info

Submission Time
Task B - Taking the middle
User aid
Language C++ (GCC 9.2.1)
Score 700
Code Size 1395 Byte
Status AC
Exec Time 74 ms
Memory 5856 KiB

Compile Error

./Main.cpp: In function ‘bool read()’:
./Main.cpp:47:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 21
Set Name Test Cases
Sample sample01.txt, sample02.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
in01.txt AC 6 ms 3580 KiB
in02.txt AC 3 ms 3804 KiB
in03.txt AC 3 ms 3564 KiB
in04.txt AC 2 ms 3712 KiB
in05.txt AC 4 ms 3684 KiB
in06.txt AC 74 ms 5852 KiB
in07.txt AC 72 ms 5848 KiB
in08.txt AC 71 ms 5816 KiB
in09.txt AC 72 ms 5720 KiB
in10.txt AC 71 ms 5844 KiB
in11.txt AC 71 ms 5736 KiB
in12.txt AC 69 ms 5716 KiB
in13.txt AC 71 ms 5836 KiB
in14.txt AC 73 ms 5736 KiB
in15.txt AC 70 ms 5828 KiB
in16.txt AC 72 ms 5776 KiB
in17.txt AC 64 ms 5656 KiB
in18.txt AC 67 ms 5856 KiB
in19.txt AC 67 ms 5736 KiB
sample01.txt AC 2 ms 3824 KiB
sample02.txt AC 2 ms 3712 KiB