結果

問題 No.3302 Sense Battle
コンテスト
ユーザー The Forsaking
提出日時 2025-10-18 20:25:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 194,212 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-18 20:25:46
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     for (int i = 1; i < n + 1; i++) scanf("%d%d", a + i, b + i);
      |                                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
int n, m, w[N];

int a[N], b[N];
ll f[5086];
int main() {
    cin >> n;
    for (int i = 1; i < n + 1; i++) scanf("%d%d", a + i, b + i);
    memset(f, -0x3f, sizeof f);
    f[0] = 0;
    for (int i = n; i; i--) {
        for (int j = n; j >= 0; j--) {
            f[j] += (ll)j * a[i];
            if (j) f[j] = max(f[j], f[j - 1] + b[i]);
        }
    }
    ll res = 0;
    for (int i = 0; i <= n; i++) res = max(res, f[i]);
    printf("%lld\n", res);
    return 0;
}
0