結果
問題 | No.2694 The Early Bird Catches The Worm |
ユーザー |
|
提出日時 | 2024-03-22 21:36:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 861 bytes |
コンパイル時間 | 2,368 ms |
コンパイル使用メモリ | 195,684 KB |
最終ジャッジ日時 | 2025-02-20 11:20:50 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 72 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> istream& operator >> (istream& is, vector<T>& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n, h; cin >> n >> h; vector<ll> a(n), b(n), as(n + 1), bs(n + 1), cs(n + 1); cin >> a >> b; for(int i = 0; i < n; i++){ as[i + 1] = as[i] + a[i]; bs[i + 1] = bs[i] + b[i]; cs[i + 1] = cs[i] + (i + 1) * b[i]; } ll ans = 0; for(int i = 0; i < n; i++){ ll ok = i, ng = n + 1, mid; while(ok + 1 < ng) { mid = (ok + ng) / 2; ll S1 = bs[mid] - bs[i]; ll S2 = cs[mid] - cs[i]; (S2 - S1 * i <= h ? ok : ng) = mid; } ans = max(ans, as[ok] - as[i]); } cout << ans << '\n'; }