답안 #696211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696211 2023-02-05T22:11:53 Z bdl Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 340 KB
#include <iostream>
using namespace std;

const int N = 2e5, Q = 2e5;

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  static long long x[N];
  for (int i = 0; i < n; i++)
    scanf("%lld", &x[i]);
  static long long mn[Q + 1], mx[Q + 1];
  long long c = 0;
  for (int i = 0; i < q; i++) {
    long long d;
    scanf("%lld", &d);
    c += d;
    mn[i + 1] = min(mn[i], c), mx[i + 1] = max(mx[i], c);
  }
  long long l = x[0] + mn[q];
  for (int i = 0; i < n - 1; i++) {
    int low = 1, hi = q;
    while (low < hi) {
      int t = (low + hi) / 2;
      if (x[i] + mx[t] >= x[i + 1] + mn[t])
        hi = t;
      else
        low = t + 1;
    }
    long long r = mn[low] == mn[low - 1] ? x[i + 1] + mn[low] : x[i] + mx[low];
    printf("%lld\n", r - l);
    l = r;
  }
  printf("%lld\n", x[n - 1] + mx[q] - l);
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d%d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%lld", &x[i]);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%lld", &d);
      |     ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -