Submission #979555

# Submission time Handle Problem Language Result Execution time Memory
979555 2024-05-11T07:45:16 Z kilkuwu Boxes with souvenirs (IOI15_boxes) C++17
Compilation error
0 ms 0 KB
#include "boxes.h"

#ifdef LOCAL
#include "template/debug.hpp"
#else 
#define dbg(...) ;
#define timer(...) ;
#endif

long long delivery(int N, int K, int L, int p[]) {
  int split = std::upper_bound(p, p + N, L / 2) - p;

  int left = split;
  int right = split;

  long long ans = 0;
  while (left >= K) {
    ans += p[left - 1] * 2;
    left -= K;
  }

  while (N - right >= K) { 
    ans += (L - p[right]) * 2;
    right += K;
  }

  // now what can we do ? 
  // we can go in either direction 

  if (right == N && left == 0) return ans;
  if (right == N || left == 0) {
    if (right == N) {
      return ans + p[left - 1] * 2;
    } else {
      return ans + (L - p[right]) * 2;
    }
  }

  // both of em are non negative

  long long naive = ans + p[left - 1] * 2 + (L - p[right]) * 2;
  // that's the naieve solution

  int tot = left + N - right;

  long long round = ans + L;

  if (tot > K) {
    int left_remain = tot - K;
    int right_remain = tot - K;
    round += std::min(p[left_remain - 1], L - p[N - right_remain]) * 2;
  }

  ans += std::min(naive, round);
  return ans;
}

#ifdef LOCAL

int main() {

  int N, K, L, i;
  std::cin >> N >> K >> L;

  int *p = (int*)malloc(sizeof(int) * (unsigned int)N);

  for (i = 0; i < N; i++) {
    std::cin >> p[i];
  }

  std::cout << delivery(N, K, L, p) << "\n";
  return 0;
}
#endif

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:11:20: error: 'upper_bound' is not a member of 'std'
   11 |   int split = std::upper_bound(p, p + N, L / 2) - p;
      |                    ^~~~~~~~~~~
boxes.cpp:51:19: error: 'min' is not a member of 'std'
   51 |     round += std::min(p[left_remain - 1], L - p[N - right_remain]) * 2;
      |                   ^~~
boxes.cpp:54:15: error: 'min' is not a member of 'std'
   54 |   ans += std::min(naive, round);
      |               ^~~