結果
| 問題 | No.3537 Thank You! |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-05-11 14:12:37 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 1,953 bytes |
| 記録 | |
| コンパイル時間 | 852 ms |
| コンパイル使用メモリ | 75,484 KB |
| 実行使用メモリ | 6,784 KB |
| 最終ジャッジ日時 | 2026-05-11 14:12:42 |
| 合計ジャッジ時間 | 3,214 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サブタスク1 | 30 % | AC * 21 |
| サブタスク2 | 70 % | AC * 15 |
| 合計 | 2.5 * 100% = 250 点 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3537.cc: No.3537 Thank You! - yukicoder
*/
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 100000;
/* typedef */
using ll = long long;
using pii = pair<int,int>;
template <typename T>
struct BIT {
int n;
vector<T> bits;
BIT() {}
BIT(int _n) { init(_n); }
void init(int _n) {
n = _n;
bits.assign(n + 1, 0);
}
T sum(int x) {
x = min(x, n);
T s = 0;
while (x > 0) {
s += bits[x];
x -= (x & -x);
}
return s;
}
void add(int x, T v) {
if (x <= 0) return;
while (x <= n) {
bits[x] += v;
x += (x & -x);
}
}
};
/* global variables */
int cs[MAX_N], ss[MAX_N];
pii ps[MAX_N];
BIT<ll> bit0, bit1;
/* subroutines */
/* main */
int main() {
int n, b;
scanf("%d%d", &n, &b);
for (int i = 0; i < n; i++) scanf("%d", cs + i);
for (int i = 0; i < n; i++) scanf("%d", ss + i);
for (int i = 0; i < n; i++) ps[i] = {cs[i], ss[i]};
sort(ps, ps + n);
for (int i = 0; i < n; i++) cs[i] = ps[i].first, ss[i] = ps[i].second;
bit0.init(n);
for (int i = 0; i < n; i++) bit0.add(i + 1, ss[i]);
bit1.init(n);
for (int i = 0; i < n; i++) bit1.add(i + 1, (ll)cs[i] * ss[i]);
if (bit1.sum(n) <= b) { printf("%lld\n", bit0.sum(n)); return 0; }
ll maxx = 0;
for (int i = 0; i < n; i++) {
if (b <= ss[i]) { maxx = b; break; }
bit0.add(i + 1, -ss[i]);
bit1.add(i + 1, -(ll)cs[i] * ss[i]);
int j0 = 0, j1 = n + 1;
int bi = b - ss[i];
while (j0 + 1 < j1) {
int j = (j0 + j1) / 2;
if (bit1.sum(j) <= bi) j0 = j;
else j1 = j;
}
//printf(" i=%d, j0=%d\n", i, j0);
ll x = (ll)ss[i] + bit0.sum(j0) + (j0 < n ? (bi - bit1.sum(j0)) / cs[j0] : 0);
maxx = max(maxx, x);
bit0.add(i + 1, ss[i]);
bit1.add(i + 1, (ll)cs[i] * ss[i]);
}
printf("%lld\n", maxx);
return 0;
}
tnakao0123