Submission #73159796


Source Code Expand

#include <bits/stdc++.h>

//#include <atcoder/all>
using namespace std;

#define lli long long int
#define REP(i, s, n) for (lli i = s; i < n; i++)
#define INF (1LL << 62)
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) #VariableName
#define LOG1(x)                                                                \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << endl;
#define LOG2(x, y)                                                             \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << endl;
#define LOG3(x, y, z)                                                          \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << " " \
         << TO_STRING(z) << "=" << z << endl;
#define LOG4(w, x, y, z)                                                       \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z        \
         << endl;
#define LOG5(w, x, y, z, a)                                                    \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << endl;
#define LOG6(w, x, y, z, a, b)                                                 \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << " " << TO_STRING(b) << "=" << b        \
         << endl;

#define overload6(a, b, c, d, e, f, g, ...) g
#define LOG(...)                                                               \
  overload6(__VA_ARGS__, LOG6, LOG5, LOG4, LOG3, LOG2, LOG1)(__VA_ARGS__)

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

mt19937 engine;
std::chrono::system_clock::time_point start, endTime;

#define DEBUG 0

void solve() {
  //  write your code here

  lli N, K;
  cin >> N >> K;

  vector<lli> H(N);
  REP(i, 0, N) { cin >> H[i]; }

  multiset<lli> ms;

  lli ans = 0;

  REP(i, 0, K) { ms.insert(H[i]); }

  REP(i, K, N + 1) {
    lli maxVal = *ms.begin();
    lli minVal = *ms.rbegin();

    chmax(ans, abs(maxVal - minVal));

    if (i == N) {
      break;
    }

    ms.erase(ms.find(H[i - K]));
    ms.insert(H[i]);
  }

  cout << ans << endl;
}

// Generated by 2.13.0 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  // Failed to predict input format

  lli N = 1;
  // cin >> N;
  while (N--)
    solve();

  return 0;
}

Submission Info

Submission Time
Task E - Temperature Fluctuation Range
User ohuton_labo
Language C++23 (GCC 15.2.0)
Score 466
Code Size 3562 Byte
Status AC
Exec Time 125 ms
Memory 14280 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 466 / 466
Status
AC × 3
AC × 75
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, 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, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, in67.txt, in68.txt, in69.txt, in70.txt, in71.txt, in72.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 3460 KiB
in02.txt AC 1 ms 3524 KiB
in03.txt AC 1 ms 3568 KiB
in04.txt AC 1 ms 3564 KiB
in05.txt AC 1 ms 3564 KiB
in06.txt AC 1 ms 3460 KiB
in07.txt AC 1 ms 3420 KiB
in08.txt AC 1 ms 3524 KiB
in09.txt AC 1 ms 3540 KiB
in10.txt AC 125 ms 9540 KiB
in11.txt AC 120 ms 12252 KiB
in12.txt AC 121 ms 12140 KiB
in13.txt AC 63 ms 4932 KiB
in14.txt AC 65 ms 4936 KiB
in15.txt AC 62 ms 4932 KiB
in16.txt AC 88 ms 14276 KiB
in17.txt AC 68 ms 4932 KiB
in18.txt AC 1 ms 3524 KiB
in19.txt AC 56 ms 14208 KiB
in20.txt AC 81 ms 9536 KiB
in21.txt AC 109 ms 14208 KiB
in22.txt AC 94 ms 9540 KiB
in23.txt AC 93 ms 9556 KiB
in24.txt AC 89 ms 9628 KiB
in25.txt AC 99 ms 9536 KiB
in26.txt AC 122 ms 11076 KiB
in27.txt AC 79 ms 4880 KiB
in28.txt AC 103 ms 14280 KiB
in29.txt AC 1 ms 3512 KiB
in30.txt AC 1 ms 3460 KiB
in31.txt AC 1 ms 3452 KiB
in32.txt AC 1 ms 3528 KiB
in33.txt AC 1 ms 3528 KiB
in34.txt AC 1 ms 3508 KiB
in35.txt AC 1 ms 3524 KiB
in36.txt AC 112 ms 9596 KiB
in37.txt AC 107 ms 11900 KiB
in38.txt AC 1 ms 3528 KiB
in39.txt AC 1 ms 3476 KiB
in40.txt AC 1 ms 3524 KiB
in41.txt AC 5 ms 3932 KiB
in42.txt AC 1 ms 3468 KiB
in43.txt AC 1 ms 3564 KiB
in44.txt AC 1 ms 3548 KiB
in45.txt AC 1 ms 3580 KiB
in46.txt AC 121 ms 11848 KiB
in47.txt AC 120 ms 11940 KiB
in48.txt AC 120 ms 11844 KiB
in49.txt AC 124 ms 8796 KiB
in50.txt AC 121 ms 11932 KiB
in51.txt AC 106 ms 9536 KiB
in52.txt AC 120 ms 11848 KiB
in53.txt AC 113 ms 9496 KiB
in54.txt AC 108 ms 11844 KiB
in55.txt AC 1 ms 3580 KiB
in56.txt AC 1 ms 3460 KiB
in57.txt AC 1 ms 3676 KiB
in58.txt AC 1 ms 3584 KiB
in59.txt AC 1 ms 3468 KiB
in60.txt AC 1 ms 3524 KiB
in61.txt AC 1 ms 3432 KiB
in62.txt AC 1 ms 3572 KiB
in63.txt AC 73 ms 9544 KiB
in64.txt AC 1 ms 3468 KiB
in65.txt AC 1 ms 3608 KiB
in66.txt AC 1 ms 3692 KiB
in67.txt AC 1 ms 3460 KiB
in68.txt AC 1 ms 3564 KiB
in69.txt AC 1 ms 3468 KiB
in70.txt AC 1 ms 3584 KiB
in71.txt AC 1 ms 3564 KiB
in72.txt AC 118 ms 9540 KiB
sample01.txt AC 1 ms 3524 KiB
sample02.txt AC 1 ms 3528 KiB
sample03.txt AC 1 ms 3528 KiB