結果
| 問題 | No.3537 Thank You! |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2026-05-08 23:19:44 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 8,335 bytes |
| 記録 | |
| コンパイル時間 | 2,514 ms |
| コンパイル使用メモリ | 341,976 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2026-05-08 23:19:55 |
| 合計ジャッジ時間 | 7,062 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サブタスク1 | 30 % | AC * 6 WA * 15 |
| サブタスク2 | 70 % | AC * 4 WA * 11 |
| 合計 | 2.5 * 0% = 0 点 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
// using mint = modint1000000007;
// const int mod = 1000000007;
// using mint = modint998244353;
// const int mod = 998244353;
// const int INF = 1e9;
// const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define P pair<long long, long long>
template<typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; }
#ifndef KWM_T_ALGORITHM_SEARCH_BINARYSEARCH_HPP
#define KWM_T_ALGORITHM_SEARCH_BINARYSEARCH_HPP
#include <cstdlib>
/**
* @brief 二分探索 (整数)
*
* @details
* 単調性を持つ述語 f(x) に対して、f(x)=true となる境界を探索する。
* 初期状態で ok は true、ng は false を満たしている必要がある。
*
* Typical Use:
* 最大/最小の条件を満たす整数を探す
*
* Complexity:
* Time: O(log |ok-ng|)
*
* Template Parameters:
* T : 整数型 (int / long long など)
* F : bool f(T) を返す関数オブジェクト
*
* Parameters:
* ok : 条件を満たす値
* ng : 条件を満たさない値
* f : 判定関数
*
* Return:
* 条件を満たす境界値
*
* Requirements:
* f(ok) == true
* f(ng) == false
*
* Notes:
* ok と ng の大小関係は問わない
*
* Example:
* ```cpp
* auto f = [&](long long x){
* return x * x <= 100;
* };
*
* long long ans = binarySearch(0LL, 11LL, f);
* ```
*
* Verified:
*
*/
namespace kwm_t::algorithm::search {
template <class T, class F>
T binarySearch(T ok, T ng, const F &f) {
while (std::abs(ok - ng) > 1) {
T mid = (ok + ng) / 2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
}
/**
* @brief 二分探索 (実数)
*
* @details
* 実数値に対する二分探索。
* 回数固定で探索を行う。
*
* Typical Use:
* 実数解の近似探索
*
* Complexity:
* Time: O(counter)
*
* Template Parameters:
* T : 浮動小数点型 (double / long double)
* F : bool f(T) を返す関数オブジェクト
*
* Parameters:
* ok : 条件を満たす値
* ng : 条件を満たさない値
* f : 判定関数
* counter : 反復回数
*
* Return:
* 条件を満たす近似値
*
* Requirements:
* f(ok) == true
* f(ng) == false
*
* Example:
* ```cpp
* auto f = [&](double x){
* return x * x <= 2.0;
* };
*
* double ans = binarySearchDouble(0.0, 2.0, f);
* ```
*
* Verified:
*
*/
namespace kwm_t::algorithm::search {
template <class T, class F>
T binarySearchDouble(T ok, T ng, const F &f, int counter = 100) {
while (counter--) {
T mid = (ok + ng) / 2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
} // namespace kwm_t::algorithm::search
#endif // KWM_T_ALGORITHM_SEARCH_BINARYSEARCH_HPP
#ifndef KWM_T_STL_SORTED_VECTOR_HPP
#define KWM_T_STL_SORTED_VECTOR_HPP
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstddef>
namespace stl {
namespace sorted_vector {
// x と等しい要素の個数
template <class T>
std::size_t count_equal(const std::vector<T>& v, const T& x) {
auto l = std::lower_bound(v.begin(), v.end(), x);
auto r = std::upper_bound(v.begin(), v.end(), x);
return std::distance(l, r);
}
// x 未満の個数
template <class T>
std::size_t count_less(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x));
}
// x 以下の個数
template <class T>
std::size_t count_leq(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x));
}
// x 以上の個数
template <class T>
std::size_t count_geq(const std::vector<T>& v, const T& x) {
return std::distance(std::lower_bound(v.begin(), v.end(), x), v.end());
}
// x より大きい個数
template <class T>
std::size_t count_greater(const std::vector<T>& v, const T& x) {
return std::distance(std::upper_bound(v.begin(), v.end(), x), v.end());
}
// [l, r) に含まれる個数
template <class T>
std::size_t count_range(const std::vector<T>& v, const T& l, const T& r) {
auto L = std::lower_bound(v.begin(), v.end(), l);
auto R = std::lower_bound(v.begin(), v.end(), r);
return std::distance(L, R);
}
// 存在判定(1個以上あるか)
template <class T>
bool contains(const std::vector<T>& v, const T& x) {
auto it = std::lower_bound(v.begin(), v.end(), x);
return it != v.end() && *it == x;
}
// 最初の出現位置(なければ v.size())
template <class T>
std::size_t first_index(const std::vector<T>& v, const T& x) {
auto it = std::lower_bound(v.begin(), v.end(), x);
return (it != v.end() && *it == x) ? std::size_t(it - v.begin()) : v.size();
}
// 最後の出現位置(なければ v.size())
template <class T>
std::size_t last_index(const std::vector<T>& v, const T& x) {
auto it = std::upper_bound(v.begin(), v.end(), x);
if (it == v.begin()) return v.size();
--it;
return (*it == x) ? std::size_t(it - v.begin()) : v.size();
}
// x 未満のうち最大の要素
template <class T>
auto it_less(const std::vector<T>& v, const T& x) {
auto it = std::lower_bound(v.begin(), v.end(), x);
if (it == v.begin()) return v.end();
--it;
return it;
}
// x 以下のうち最大の要素
template <class T>
auto it_leq(const std::vector<T>& v, const T& x) {
auto it = std::upper_bound(v.begin(), v.end(), x);
if (it == v.begin()) return v.end();
--it;
return it;
}
// x 以上のうち最小の要素
template <class T>
auto it_geq(const std::vector<T>& v, const T& x) {
return std::lower_bound(v.begin(), v.end(), x);
}
// x より大きい最小の要素
template <class T>
auto it_greater(const std::vector<T>& v, const T& x) {
return std::upper_bound(v.begin(), v.end(), x);
}
// x の最初の出現位置(なければ v.end())
template <class T>
auto it_first(const std::vector<T>& v, const T& x) {
auto it = std::lower_bound(v.begin(), v.end(), x);
if (it != v.end() && *it == x) return it;
return v.end();
}
// x の最後の出現位置(なければ v.end())
template <class T>
auto it_last(const std::vector<T>& v, const T& x) {
auto it = std::upper_bound(v.begin(), v.end(), x);
if (it == v.begin()) return v.end();
--it;
if (*it == x) return it;
return v.end();
}
} // namespace sorted_vector
} // namespace stl
#endif // KWM_T_STL_SORTED_VECTOR_HPP
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, b; cin >> n >> b;
vector<P>cs(n);
rep(i, n)cin >> cs[i].first;
rep(i, n)cin >> cs[i].second;
sort(all(cs));
vector<long long>c(n), sc(n + 1);// gaku
vector<long long>s(n), ss(n + 1);// maisu
rep(i, n)c[i] = cs[i].first, s[i] = cs[i].second;
rep(i, n)sc[i + 1] = sc[i] + c[i] * s[i];
rep(i, n)ss[i + 1] = ss[i] + s[i];
//rep(i, n) {
// cout << cs[i].first << " " << cs[i].second << endl;
//}cout << endl;
//rep(i, n + 1)cout << sc[i] << endl;
long long ans = 0;
rep(i, n) {
// i = 9;
// iを1円にする
auto g = [&](long long n) {
long long cn = n;
// n枚買うのにかかる価格?
int idx = stl::sorted_vector::count_leq(ss, n);// 以下の数
long long ret = sc[idx - 1];
n -= ss[idx - 1];
if (n)ret += n * c[idx];
//cout << cn << "_" << ret << endl;
return ret;
};
auto f = [&](const long long x) {
// x枚買える?
int idx = stl::sorted_vector::count_leq(ss, x);// 以下の数
if (idx <= i) {
long long tmp = min(s[i], x);
long long val = tmp + g(x - tmp);
//cout << x << " " << val << endl;
return val <= b;
}
else {
long long val = g(x);
// cout << x << " " << val << s[i] << "__" << c[i] << endl;
val -= s[i] * c[i] - s[i];
// cout << x << " " << val << s[i] << "__" << c[i] << endl;
return val <= b;
}
};
auto tmp = kwm_t::algorithm::search::binarySearch<long long>(0, ss.back() + 1, f);
//cout << i << " " << tmp << endl;
chmax(ans, tmp);
//break;
}
cout << ans << endl;
return 0;
}
kwm_t