結果

問題 No.2139 K Consecutive Sushi
ユーザー daiotadaiota
提出日時 2022-12-11 23:41:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 1,289 ms
コンパイル使用メモリ 166,060 KB
実行使用メモリ 11,316 KB
最終ジャッジ日時 2023-08-05 21:40:07
合計ジャッジ時間 4,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 73 ms
11,040 KB
testcase_04 AC 83 ms
11,036 KB
testcase_05 AC 73 ms
11,088 KB
testcase_06 AC 69 ms
11,064 KB
testcase_07 AC 75 ms
11,108 KB
testcase_08 AC 79 ms
11,096 KB
testcase_09 AC 80 ms
11,316 KB
testcase_10 AC 82 ms
11,052 KB
testcase_11 AC 83 ms
11,140 KB
testcase_12 AC 78 ms
11,180 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 25 ms
5,092 KB
testcase_25 AC 59 ms
10,620 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 22 ms
5,008 KB
testcase_28 AC 21 ms
4,956 KB
testcase_29 AC 10 ms
4,376 KB
testcase_30 AC 27 ms
8,000 KB
testcase_31 AC 71 ms
10,952 KB
testcase_32 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)



ll a[200010];

#define T 200010
#define INF 1e18
ll n,N,tree[4*T];

void init(){
  n=1;
  while(n<N) n*=2;
  REP(i,2*n) tree[i]=INF;
}

void update(ll k, ll a){
  k=n-1+k;
  tree[k]=a;
  while(k>0){
    k=(k-1)/2;
    tree[k]=min(tree[2*k+1], tree[2*k+2]);
  }
}

ll query(ll a, ll b, ll k, ll l, ll r){
  if(r<=a || b<=l) return INF;
  if(a<=l && r<=b) return tree[k];
  else return min(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
}


int main(void){
	ll i;

	cin.tie(0);  ios_base::sync_with_stdio(false);

	ll K;
	cin >> N >> K;
	ll S=0;
	for(i=1;i<=N;i++){
		cin >> a[i];
		S+=a[i];
	}

	N++;

	init();

	update(0,0);

	for(i=1;i<=N;i++){

		ll mn=query(max(i-K,0LL),i,0,0,n);
		update(i,a[i]+mn);

		if(i==N){
			cout << S-a[i]-mn << endl;
			return 0;
		}



	}





	return 0;
}
0