救救孩子吧
查看原帖
救救孩子吧
677234
FstAutoMaton楼主2024/8/16 13:49

拍了2h了,一个hack都没拍出来,但是交上去WA了90+。

// STOOOOOOOOOOOOOOOO hzt CCCCCCCCCCCCCCCCOTZ
#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using Pii = pair<LL, LL>;

const int kMaxN = 2e5 + 5, kL = 31;
const LL kInf = 3e13;

struct A {
  LL x, y;

  bool operator<(const A &a) const {
    return y * (a.x - 1) < a.y * (x - 1);
  }
} a[kMaxN], b[kMaxN], c[kMaxN];

LL s[kMaxN][35], tot, cnt, n, m;
Pii f[kMaxN];

LL Val(Pii x, LL y) {
  return x.first - x.second * y;
}

Pii operator+(Pii x, Pii y) {
  return Pii{x.first + y.first, x.second + y.second};
}

Pii Min(Pii x, Pii y) {
  return x.first == y.first ? (y.second > x.second ? y : x) : (x.first < y.first ? x : y);
}

bool Check(LL x) {
  f[0] = {0, 0};
  for (int i = 1; i <= n; i++) {
    f[i] = {kInf, kInf};
    for (int j = 1; j <= min(kL - 1, i); j++) {
      f[i] = Min(f[i], f[i - j] + Pii{s[i][j] + x, 1});
    }
  }
  // cout << f[n].first << " " << f[n].second << "\n";
  return Val(f[n], x) <= m;
}

int main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  LL t = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].x == 1) {
      b[++cnt] = a[i];
      t += a[i].y;
    } else {
      a[++tot] = a[i];
    }
  }
  n = tot;
  if (!n) {
    cout << 1 << " " << t << "\n";
    return 0;
  }
  m -= t;
  for (int i = 1; i <= n; i++) {
    int p = max(1, i - kL + 2), v = 0;
    for (int j = i; j >= p; j--) {
      c[++v] = a[j];
      sort(c + 1, c + v + 1);
      LL x = 0;
      for (int k = 1; k <= v; k++) {
        x = min(x * c[k].x + c[k].y, kInf);
      }
      s[i][i - j + 1] = x;
    }
  }
  LL l = 1, r = kInf;
  // check(x):每多一段加上x
  for (LL mid; l < r; Check(mid) ? l = mid : r = mid - 1) {
    mid = l + r + 1 >> 1;
  }
  // l = 4;
  Check(l);
  LL val = (m - Val(f[n], l)) / l;
  f[n] = f[n] + Pii{0, -val};
  cout << f[n].second << " " << Val(f[n], l) + t;
  return 0;
}
2024/8/16 13:49
加载中...