Submission #68153658


Source Code Expand

#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)

#if __has_include("shik/dump.h")
#include "shik/dump.h"
#else
#define dump(...) 0
#endif

using namespace std;

const int N = 10010;
const int M = 5e5 + 10;

int n, m, p[N], a[N], b[N];
int qs[M];
void input() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i] >> a[i] >> b[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> qs[i];
}

const int K = 510;
int dp[N][K];

int go(int pos, int mood) {
  if (mood < 0) mood = 0;
  if (pos == n) return mood;
  if (mood < K && dp[pos][mood] != -1) return dp[pos][mood];
  int d = p[pos] >= mood ? a[pos] : -b[pos];
  int ans = go(pos + 1, mood + d);
  if (mood < K) dp[pos][mood] = ans;
  return ans;
}

int sb[N];
int solve(int q) {
  int lo = 0, hi = n;
  while (lo != hi) {
    int mid = (lo + hi) >> 1;
    if (q - sb[mid] > 500) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }
  int mood = q - sb[lo];
  int ans = go(lo, mood);
  return ans;
}

void solve() {
  for (int i = 0; i < n; i++) sb[i + 1] = sb[i] + b[i];
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m; i++) {
    int ans = solve(qs[i]);
    cout << ans << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  input();
  solve();
  return 0;
}

Submission Info

Submission Time
Task D - Takahashi's Expectation
User shik
Language C++ 23 (gcc 12.2)
Score 425
Code Size 1476 Byte
Status AC
Exec Time 165 ms
Memory 27808 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 9 ms 23464 KiB
00_sample_01.txt AC 9 ms 23388 KiB
00_sample_02.txt AC 10 ms 23388 KiB
01_random_03.txt AC 66 ms 27696 KiB
01_random_04.txt AC 66 ms 27576 KiB
01_random_05.txt AC 65 ms 27736 KiB
01_random_06.txt AC 66 ms 27548 KiB
01_random_07.txt AC 66 ms 27760 KiB
01_random_08.txt AC 66 ms 27728 KiB
01_random_09.txt AC 66 ms 27608 KiB
01_random_10.txt AC 66 ms 27736 KiB
01_random_11.txt AC 66 ms 27660 KiB
01_random_12.txt AC 65 ms 27724 KiB
01_random_13.txt AC 66 ms 27628 KiB
01_random_14.txt AC 69 ms 27676 KiB
01_random_15.txt AC 66 ms 27616 KiB
01_random_16.txt AC 27 ms 24036 KiB
01_random_17.txt AC 31 ms 24256 KiB
01_random_18.txt AC 61 ms 27060 KiB
01_random_19.txt AC 20 ms 23896 KiB
01_random_20.txt AC 23 ms 24228 KiB
01_random_21.txt AC 61 ms 27140 KiB
01_random_22.txt AC 61 ms 27296 KiB
01_random_23.txt AC 39 ms 24480 KiB
01_random_24.txt AC 65 ms 27796 KiB
01_random_25.txt AC 66 ms 27684 KiB
01_random_26.txt AC 65 ms 27536 KiB
01_random_27.txt AC 165 ms 27808 KiB
01_random_28.txt AC 69 ms 27764 KiB
01_random_29.txt AC 66 ms 27696 KiB