結果

問題 No.1148 土偶Ⅲ
ユーザー minhvietzz
提出日時 2026-08-14 10:38:07
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,012 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,563 ms
コンパイル使用メモリ 364,916 KB
実行使用メモリ 9,416 KB
最終ジャッジ日時 2026-08-14 10:38:14
合計ジャッジ時間 4,658 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 2 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define ll long long 
#define endl "\n"
#define fi first 
#define se second 
#define pb push_back
#define ins insert 
#define dttn ios::sync_with_stdio(false);cin.tie(nullptr);

using namespace std;
const int mxn = 100005;
const int HINF = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll bit[mxn];
void update(int id, ll val, int m){
    for(; id <= m; id += id & -id){
        bit[id] = max(bit[id], val);
    }
}

ll query(int id){
    ll res = 0;
    for(; id > 0; id -= id & -id){
        res = max(res, bit[id]);
    }
    return res;
}

int main(){
    dttn
    if(fopen("wiseq.inp", "r")){
        freopen("wiseq.inp", "r", stdin);
        freopen("wiseq.out", "w", stdout);
    }
    int n, k;
    cin >> n >> k;
    vector<ll> a(n + 1);
    ll s = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        s += a[i];
    }
    if(k == s){
        vector<ll> dp;
        for(int i = 1; i <= n; i++){
            auto it = lower_bound(dp.begin(), dp.end(), a[i]);
            if(it == dp.end()) dp.pb(a[i]);
            else *it = a[i];
        }
        cout << dp.size();
    }
    else{
        vector<ll> v;
        for(int i = 1; i <= n; i++){
            v.pb(a[i]);
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        int m = v.size();
        ll ans = 0;
        int res = 0;
        vector<ll> ta;
        for(int i = 1; i <= n; i++){
            int r = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
            ll mx = query(r - 1);
            if(a[i] + mx <= k){
                ll dp = a[i] + mx;
                ans = max(ans, dp);
                update(r, dp, m);
                auto it = lower_bound(ta.begin(), ta.end(), a[i]);
                if(it == ta.end()){
                    ta.pb(a[i]);
                }
                else *it = a[i];
                int m = ta.size();
                res = max(res, m);
            }
        }
        cout << res;
    }
    return 0;
}
0