結果

問題 No.2546 Many Arithmetic Sequences
ユーザー 👑 NachiaNachia
提出日時 2023-11-23 22:39:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,784 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 89,944 KB
実行使用メモリ 25,048 KB
最終ジャッジ日時 2023-11-25 01:26:51
合計ジャッジ時間 4,889 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 55 ms
10,228 KB
testcase_04 AC 89 ms
12,336 KB
testcase_05 AC 73 ms
9,976 KB
testcase_06 AC 16 ms
6,676 KB
testcase_07 AC 37 ms
6,676 KB
testcase_08 AC 11 ms
6,676 KB
testcase_09 AC 34 ms
8,980 KB
testcase_10 AC 60 ms
11,360 KB
testcase_11 AC 71 ms
17,432 KB
testcase_12 AC 28 ms
7,280 KB
testcase_13 AC 59 ms
11,084 KB
testcase_14 AC 66 ms
15,456 KB
testcase_15 AC 19 ms
6,676 KB
testcase_16 AC 64 ms
14,472 KB
testcase_17 AC 81 ms
14,608 KB
testcase_18 AC 49 ms
9,292 KB
testcase_19 AC 55 ms
10,324 KB
testcase_20 AC 36 ms
8,780 KB
testcase_21 AC 38 ms
8,320 KB
testcase_22 AC 69 ms
11,352 KB
testcase_23 AC 127 ms
19,256 KB
testcase_24 AC 127 ms
19,264 KB
testcase_25 AC 131 ms
19,252 KB
testcase_26 AC 123 ms
19,268 KB
testcase_27 AC 125 ms
19,260 KB
testcase_28 AC 100 ms
25,048 KB
testcase_29 AC 98 ms
25,048 KB
testcase_30 AC 103 ms
25,048 KB
testcase_31 AC 101 ms
25,048 KB
testcase_32 AC 104 ms
25,048 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 91 ms
18,624 KB
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// wrong answer
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <atcoder/modint>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(i64 i=0; i<(i64)(n); i++)
#define repr(i,n) for(i64 i=(i64)(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;


int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 N, M; cin >> N >> M;
    vector<pair<i64, i64>> A, B;
    rep(i,N){
        i64 a,d; cin >> a >> d;
        if(d <= 0) B.push_back({ d, a });
        else A.push_back({ d, a });
    }
    auto nthTerm = [](i64 d, i64 a, i64 n) -> i64 {
        return a + d * n;
    };
    auto prefixSum = [](i64 d, i64 a, i64 n) -> i64 {
        i64 ans = a * n;
        ans += d * ((n*n-n)/2);
        return ans;
    };
    vector<i64> valdown;
    {
        int n = B.size();
        vector<int> ptr(n);
        priority_queue<pair<i64, i64>> que;
        rep(v,n){
            auto [d,a] = B[v];
            que.push({ nthTerm(d, a, ptr[v]), v });
        }
        rep(i,M){
            auto [p,v] = que.top(); que.pop();
            valdown.push_back(p);
            ptr[v]++;
            auto [d,a] = B[v];
            que.push({ nthTerm(d, a, ptr[v]), v });
        }
    }
    vector<i64> valdownSum(M+1);
    rep(i,M) valdownSum[i+1] = valdownSum[i] + valdown[i];
    i64 ans = valdownSum[M];
    for(auto [d,a] : A){
        i64 ok = 0, ng = M+1;
        while(ok + 1 < ng){
            i64 x = (ok + ng) / 2;
            if(nthTerm(d,a,x-1) >= valdown[M-x]) ok = x; else ng = x;
        }
        ans = max(ans, valdownSum[M-ok] + prefixSum(d,a,ok));
    }
    cout << ans << endl;
    return 0;
}
0