提出 #29492199


ソースコード 拡げる

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

using ll = long long;

template <class F> ll optimize(int low, int high, const F& f) {
    while (high - low > 2) {
        const int m1 = (low + high) / 2;
        const int m2 = m1 + 1;
        if (f(m1) < f(m2)) {
            low = m1;
        } else {
            high = m2;
        }
    }
    return f(low + 1);
}

void solve() {
    int n, m;
    cin >> n >> m;
    ll a = 0, b = 0, ans = numeric_limits<ll>::min();
    for (int i = 0; i < n; ++i) {
        ll x, y;
        cin >> x >> y;
        const auto f = [&](const int k) {
            return a + b * k + x * k * (k + 1) / 2;
        };
        if (x > 0) {
            ans = max(ans, f(1));
            ans = max(ans, f(y));
        } else {
            ans = max(ans, optimize(0, y + 1, f));
        }
        a = f(y);
        b += x * y;
    }
    cout << ans << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

提出情報

提出日時
問題 F - Sum Sum Max
ユーザ KoD
言語 C++ (GCC 9.2.1)
得点 500
コード長 1029 Byte
結果 AC
実行時間 486 ms
メモリ 3596 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 12
セット名 テストケース
Sample example_00.txt
All example_00.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 8 ms 3528 KiB
test_00.txt AC 486 ms 3576 KiB
test_01.txt AC 96 ms 3436 KiB
test_02.txt AC 86 ms 3596 KiB
test_03.txt AC 77 ms 3400 KiB
test_04.txt AC 75 ms 3596 KiB
test_05.txt AC 78 ms 3524 KiB
test_06.txt AC 75 ms 3416 KiB
test_07.txt AC 85 ms 3596 KiB
test_08.txt AC 63 ms 3528 KiB
test_09.txt AC 43 ms 3532 KiB
test_10.txt AC 178 ms 3412 KiB