Submission #1674516


Source Code Expand

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

template<class T>
class RMQ {
public:
	vector<T> data;
	vector<vector<int> > block;
	vector<int> sblock;
	int N;
	// int lg;
	
	// if Range_MAximam_Query -> return data[b] > data[a] ? b : a
	int argMin(int a, int b) {
		return data[b] < data[a] ? b : a;
	}
	// x の下位 y bit を 0 にする
	int maskBits(int x, int y) {
		return (x >> y) << y;
	}
	RMQ(vector<T> &v) {
		data = v;
		N = data.size();

		// lg = 32 - __builtin_clz(N);

		int blockSize = ((N - 1) >> 5) + 1;
		block.assign(blockSize, vector<int>(32, 0));
		for(int i = 0; i < N; i++) {
			if(i % 32 == 0) block[i >> 5][0] = i;
			block[i >> 5][0] = argMin(block[i >> 5][0], i);
		}

		for(int j = 1; j < block[0].size(); j++) {
			for(int i = 0; i < block.size(); i++) {
				block[i][j] = argMin(block[i][j - 1], block[min(i + (1 << (j - 1)), (int)block.size() - 1)][j - 1]);
			}
		}

		sblock.assign(N, 0);
		vector<int> st(32);
		int stackSize = 0;
		for(int i = 0; i < N; i++) {
			if(i % 32 == 0) stackSize = 0;
			while(stackSize && i == argMin(i, st[stackSize - 1])) --stackSize;
			if(stackSize) {
				int g = st[stackSize - 1];
				sblock[i] = sblock[g] | (1 << (g % 32));
			}
			st[stackSize++] = i;
		}
	}

	// min{data[i] : i in [l .. r]}
	T query(int l, int r) {
		if(l == r) return data[l];
		int l1 = (l >> 5) + 1;
		int r1 = (r >> 5) - 1;
		int ret = l;

		if(l1 <= r1) { // calc sparse table
			int d = r1 - l1 + 1;
			if(d <= 2) {
				ret = argMin(ret, argMin(block[l1][0], block[r1][0]));
			}
			else {
				int lg2 = 32 - __builtin_clz(d) - 1;
				ret = argMin(ret, argMin(block[l1][lg2], block[r1 - (1 << lg2) + 1][lg2]));
			}
		}

		if(l1 - r1 == 2) { // same block
			int t = maskBits(sblock[r], l % 32);
			if(t == 0) {
				ret = argMin(ret, r);
			}
			else {
				ret = argMin(ret, __builtin_ctz(t) + ((l1 - 1) << 5));
			}
		}
		else { // other block
			int t1 = maskBits(sblock[(l1 << 5) - 1], l % 32);
			if(t1 == 0) {
				ret = argMin(ret, (l1 << 5) - 1);
			}
			else {
				ret = argMin(ret, __builtin_ctz(t1) + ((l1 - 1) << 5));
			}

			int t2 = sblock[r];
			if(t2 == 0) {
				ret = argMin(ret, r);
			}
			else {
				ret = argMin(ret, __builtin_ctz(t2) + ((r1 + 1) << 5));
			}
		}

		return data[ret];
	}
};


void mainmain(){
	int n,m,K;
	cin>>n>>m>>K;
	vll dp(n);
	vll in(n);
	rep(i,n){
		cin>>dp[i];
		in[i]=dp[i];
		dp[i]*=-1;
	}
	rep(k, 2, K+1){
		RMQ<ll> rmq(dp);
		vll next(n);
		rep(i,k-1,n){
			next[i]=rmq.query(max(0, i-m),i-1)-in[i]*k;
		}
		dp=next;
	}
	ll ans = 0;
	// rep(i,n) cout<<-dp[i]<<" ";
	// cout<<endl;
	rep(i,n) mins(ans, dp[i]);
	cout<<-ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Submission Info

Submission Time
Task A - Struck Out
User j_gui0121
Language C++14 (GCC 5.4.1)
Score 700
Code Size 4885 Byte
Status AC
Exec Time 1178 ms
Memory 4360 KB

Judge Result

Set Name Sample subtask1 subtask2 subtask3 All
Score / Max Score 0 / 0 100 / 100 200 / 200 300 / 300 100 / 100
Status
AC × 3
AC × 10
AC × 12
AC × 21
AC × 46
Set Name Test Cases
Sample sample_1.txt, sample_2.txt, sample_3.txt
subtask1 sample_2.txt, subtask_1_1.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
subtask2 sample_1.txt, sample_2.txt, sample_3.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt
subtask3 sample_1.txt, sample_2.txt, sample_3.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt, subtask_3_9.txt
All sample_1.txt, sample_2.txt, sample_3.txt, sample_1.txt, sample_2.txt, sample_3.txt, subtask_1_1.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt, subtask_3_9.txt, subtask_4_1.txt, subtask_4_10.txt, subtask_4_11.txt, subtask_4_12.txt, subtask_4_13.txt, subtask_4_2.txt, subtask_4_3.txt, subtask_4_4.txt, subtask_4_5.txt, subtask_4_6.txt, subtask_4_7.txt, subtask_4_8.txt, subtask_4_9.txt
Case Name Status Exec Time Memory
sample_1.txt AC 1 ms 256 KB
sample_2.txt AC 1 ms 256 KB
sample_3.txt AC 1 ms 256 KB
subtask_1_1.txt AC 1 ms 256 KB
subtask_1_2.txt AC 108 ms 720 KB
subtask_1_3.txt AC 1157 ms 4360 KB
subtask_1_4.txt AC 7 ms 512 KB
subtask_1_5.txt AC 28 ms 4352 KB
subtask_1_6.txt AC 2 ms 256 KB
subtask_1_7.txt AC 392 ms 4360 KB
subtask_1_8.txt AC 1156 ms 4360 KB
subtask_1_9.txt AC 5 ms 256 KB
subtask_2_1.txt AC 2 ms 256 KB
subtask_2_2.txt AC 2 ms 256 KB
subtask_2_3.txt AC 2 ms 256 KB
subtask_2_4.txt AC 2 ms 256 KB
subtask_2_5.txt AC 1 ms 256 KB
subtask_2_6.txt AC 1 ms 256 KB
subtask_2_7.txt AC 2 ms 256 KB
subtask_2_8.txt AC 1 ms 256 KB
subtask_2_9.txt AC 2 ms 256 KB
subtask_3_1.txt AC 126 ms 4356 KB
subtask_3_2.txt AC 127 ms 4356 KB
subtask_3_3.txt AC 122 ms 4356 KB
subtask_3_4.txt AC 100 ms 3548 KB
subtask_3_5.txt AC 6 ms 512 KB
subtask_3_6.txt AC 67 ms 4352 KB
subtask_3_7.txt AC 125 ms 4356 KB
subtask_3_8.txt AC 13 ms 720 KB
subtask_3_9.txt AC 125 ms 4356 KB
subtask_4_1.txt AC 1176 ms 4360 KB
subtask_4_10.txt AC 862 ms 4360 KB
subtask_4_11.txt AC 1013 ms 4356 KB
subtask_4_12.txt AC 1021 ms 4360 KB
subtask_4_13.txt AC 1082 ms 4360 KB
subtask_4_2.txt AC 1178 ms 4356 KB
subtask_4_3.txt AC 1157 ms 4356 KB
subtask_4_4.txt AC 1178 ms 4356 KB
subtask_4_5.txt AC 1003 ms 4356 KB
subtask_4_6.txt AC 98 ms 4352 KB
subtask_4_7.txt AC 626 ms 4356 KB
subtask_4_8.txt AC 1162 ms 4300 KB
subtask_4_9.txt AC 524 ms 4356 KB