結果
| 問題 |
No.2139 K Consecutive Sushi
|
| コンテスト | |
| ユーザー |
pitP
|
| 提出日時 | 2022-12-19 11:21:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 2,000 ms |
| コード長 | 4,865 bytes |
| コンパイル時間 | 4,369 ms |
| コンパイル使用メモリ | 256,444 KB |
| 最終ジャッジ日時 | 2025-02-09 16:59:04 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); }
istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }
istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); }
typedef long long ll;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define rep(i,n) for (int i = 0;i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define my_sort(x) sort(x.begin(), x.end())
#define my_max(x) *max_element(all(x))
#define my_min(x) *min_element(all(x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;
const int MOD = 998244353;
const int MOD2 = 1e9+7;
const double PI = acos(-1);
vector<int> di = {1,0,-1,0};
vector<int> dj = {0,1,0,-1};
template<typename T>
void print_2dvector(vector<vector<T>> &vec){
int H = vec.size();
for(int i=0;i<H;i++){
cout << i << ' ' << '[';
for(int j=0;j<vec[i].size();j++){
if (j) cout << ',' << ' ';
cout << vec[i][j];
}
cout << ']' << endl;
}
}
template<typename T>
void print_vector(vector<T> &vec){
int N = vec.size();
cout << '[';
for(int i=0;i<N;i++){
if (i) cout << ',' << ' ';
cout << vec[i];
}
cout << ']' << endl;
}
template <class T, T (*op)(T,T), T (*e)()>
struct SWAG {
vector<T> top, bottom, topfold, bottomfold;
SWAG(){
topfold.push_back(e());
bottomfold.push_back(e());
}
void _pushbottom(T x){
bottom.push_back(x);
bottomfold.push_back(op(bottomfold.back(), x));
}
T _popbottom(){
auto res = bottom.back();
bottom.pop_back();
bottomfold.pop_back();
return res;
}
void _pushtop(T x){
top.push_back(x);
topfold.push_back(op(x, topfold.back()));
}
T _poptop(){
auto res = top.back();
top.pop_back();
topfold.pop_back();
return res;
}
void push(T x){
_pushbottom(x);
}
void pushleft(T x){
_pushtop(x);
}
T fold(){
return op(topfold.back(), bottomfold.back());
}
T popleft(){
if (top.empty()){
vector<T> stack_;
while(!bottom.empty()){
auto x = _popbottom();
stack_.push_back(x);
}
int N = stack_.size();
reverse(all(stack_));
vector<T> stack1, stack2;
for(int i=0;i<N;i++){
if (i < (N+1)/2) stack1.push_back(stack_[i]);
else stack2.push_back(stack_[i]);
}
reverse(all(stack2));
for(int i=0;i<(N+1)/2;i++){
_pushtop(stack1.back());
stack1.pop_back();
}
for(int i=0;i<(N/2);i++){
_pushbottom(stack2.back());
stack2.pop_back();
}
}
if (top.empty()) return e();
else return _poptop();
}
T pop(){
if (bottom.empty()){
vector<T> stack_;
while(!top.empty()){
auto x = _poptop();
stack_.push_back(x);
}
int N = stack_.size();
vector<T> stack1, stack2;
for(int i=0;i<N;i++){
if (i < (N/2)) stack1.push_back(stack_[i]);
else stack2.push_back(stack_[i]);
}
reverse(all(stack2));
for(int i=0;i<(N+1)/2;i++){
_pushtop(stack2.back());
stack2.pop_back();
}
for(int i=0;i<(N/2);i++){
_pushtop(stack1.back());
stack1.pop_back();
}
}
if (bottom.empty()) return e();
else return _popbottom();
}
};
using S = ll;
S op(S a, S b){return min(a, b);}
S e(){return LINF;}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
SWAG<S,op,e> sw;
int N,K; cin >> N >> K;
vector<ll> A(N);
rep(i,N) cin >> A[i];
ll ans = 0ll;
rep(i,N) ans += A[i];
for(int i=0;i<K;i++){
sw.push(A[i]);
}
for(int i=K;i<N;i++){
sw.push(sw.fold() + A[i]);
sw.popleft();
}
ans -= sw.fold();
cout << ans << endl;
}
pitP