結果

問題 No.2698 Many Asakatsu
ユーザー emthrm
提出日時 2024-03-22 23:13:24
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,792 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 246,632 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-30 12:28:16
合計ジャッジ時間 10,651 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

ll aripro(const int a, const int d, const int n) {
  return n * (a * 2 + (n - 1LL) * d) / 2;
}

ll d(const int a, const int b, const int m, const ll r) {
  if (a > r) return aripro(a, b, m) - r * m;
  int lb = 0, ub = m;
  while (ub - lb > 1) {
    const int mid = midpoint(lb, ub);
    (a + ll{b} * mid <= r ? lb : ub) = mid;
  }
  return r * (lb + 1) - aripro(a, b, lb + 1) + aripro(a + b * (lb + 1LL), b, m - (lb + 1)) - r * (m - (lb + 1));
}

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(n), b(n); REP(i, n) cin >> a[i] >> b[i];
  int q; ll x; cin >> q >> x;
  vector<int> c(n);
  for (int& c_i : c) cin >> c_i;
  int i = 0;
  REP(tm, q) {
    while (i + 1 < n && d(a[i], b[i], m, x) > d(a[i + 1], b[i + 1], m, x)) ++i;
    ll diff = LINF;
    int ans = -1;
    FOR(j, max(i - 10, 0), min(i + 11, n)) {
      if (chmin(diff, d(a[j], b[j], m, x))) ans = j;
    }
    cout << ans + 1 << " \n"[tm + 1 == q];
    x += c[ans];
  }
  return 0;
}
0