Submission #2915353


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def -infl
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l,r); };
    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x,int y,int l=0,int r=NV,int k=1){if(r<=x||y<=l)return def;if(x<=l&&r<=y)return val[k];
    auto a=get(x,y,l,(l+r)/2,k*2);auto b=get(x,y,(l+r)/2,r,k*2+1);return comp(a,b);}
    void update(int i, V v) { i+=NV;val[i]=v;while(i>1)i>>=1,val[i]=comp(val[i*2],val[i*2+1]); }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
 
int N, K, B[201010];
//ll dp[201010];
SegTree<ll, 1 << 18> dp;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> B[i];

    /*dp[0] = 0;
    rep(i, 0, N) {
        dp[i + 1] = dp[i] + B[i];
        rep(j, 0, i - K + 2) chmax(dp[i + 1], dp[j]);
    }*/

    dp.update(0, 0);
    rep(i, 0, N) {
        ll res = dp[i] + B[i];
        chmax(res, dp.get(0, i - K + 2));
        dp.update(i + 1, res);
    }
 
    cout << dp[N] << endl;
}

Submission Info

Submission Time
Task B - Neutralize
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2396 Byte
Status AC
Exec Time 70 ms
Memory 5120 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 44
Set Name Test Cases
Sample a01, a02, a03, a04
All a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44
Case Name Status Exec Time Memory
a01 AC 3 ms 4352 KB
a02 AC 3 ms 4352 KB
a03 AC 3 ms 4352 KB
a04 AC 3 ms 4352 KB
b05 AC 2 ms 4352 KB
b06 AC 2 ms 4352 KB
b07 AC 7 ms 4480 KB
b08 AC 52 ms 5120 KB
b09 AC 68 ms 5120 KB
b10 AC 51 ms 5120 KB
b11 AC 51 ms 5120 KB
b12 AC 3 ms 4352 KB
b13 AC 55 ms 5120 KB
b14 AC 55 ms 5120 KB
b15 AC 68 ms 5120 KB
b16 AC 68 ms 5120 KB
b17 AC 68 ms 5120 KB
b18 AC 68 ms 5120 KB
b19 AC 67 ms 5120 KB
b20 AC 66 ms 5120 KB
b21 AC 55 ms 5120 KB
b22 AC 59 ms 5120 KB
b23 AC 67 ms 5120 KB
b24 AC 51 ms 4992 KB
b25 AC 64 ms 5120 KB
b26 AC 66 ms 5120 KB
b27 AC 54 ms 5120 KB
b28 AC 63 ms 5120 KB
b29 AC 61 ms 5120 KB
b30 AC 38 ms 4736 KB
b31 AC 66 ms 5120 KB
b32 AC 62 ms 5120 KB
b33 AC 52 ms 4992 KB
b34 AC 61 ms 5120 KB
b35 AC 57 ms 5120 KB
b36 AC 68 ms 5120 KB
b37 AC 70 ms 5120 KB
b38 AC 69 ms 5120 KB
b39 AC 69 ms 5120 KB
b40 AC 69 ms 5120 KB
b41 AC 64 ms 5120 KB
b42 AC 69 ms 5120 KB
b43 AC 65 ms 5120 KB
b44 AC 68 ms 5120 KB