結果

問題 No.2217 Suffix+
ユーザー xiachi00xiachi00
提出日時 2023-07-01 16:08:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 194,884 KB
最終ジャッジ日時 2025-02-15 05:20:55
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /usr/include/c++/13/istream:41,
                 from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from main.cpp:1:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’,
    inlined from ‘int main()’ at main.cpp:36:13:
/usr/include/c++/13/ostream:204:25: warning: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  204 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:26:19: note: ‘res’ was declared here
   26 |     LL l, r, mid, res;
      |                   ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

int main() {
    ios_base::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vector<LL> a(n);
    for (LL &x : a) cin >> x;
    auto check = [&](LL s) {
        LL sum = 0, w;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] + sum < s) {
                w = (s - a[i] - sum + i) / (i + 1);
                if (cnt + w > k) return false;
                sum += w * (i + 1), cnt += w;
            }
        }
        return true;
    };

    LL l, r, mid, res;
    l = 0, r = 1E18;
    while (l <= r) {
        mid = l + r >> 1;
        if (check(mid)) {
            l = (res = mid) + 1;
        } else {
            r = mid - 1;
        }
    }
    cout << res;

    return 0;
}
0