結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー WebP
提出日時 2026-09-05 13:18:44
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 293 ms / 2,000 ms
+ 272µs
コード長 1,667 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,078 ms
コンパイル使用メモリ 380,392 KB
実行使用メモリ 285,952 KB
最終ジャッジ日時 2026-09-05 13:18:56
合計ジャッジ時間 11,046 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#line 3 "/home/WebP/kyopro/cp-library/lib/util.hpp"
using namespace std;

using ll = long long;
using ld = long double;
template<class T> using greater_queue = priority_queue<T,vector<T>,greater<T>>;
#define rep(i,s,n) for (int i = (s); i < (n); i++)
#define rep1(i,s,n) for (int i = (s); i <= (n); i++)
#define REP(i,n,s) for (int i = (n)-1; i >= s; i--)
#define REP1(i,n,s) for (int i = (n); i >= s; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
inline void YesNo(const bool& b) { cout << (b ? "Yes\n" : "No\n"); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T>
constexpr bool chmax(T& a, const T& b) {
	if (a >= b) return false;
	a = b;
	return true;
}
template<class T>
constexpr bool chmin(T& a, const T& b) {
	if (a <= b) return false;
	a = b;
	return true;
}
#line 7 "main.cpp"

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,0,n) cin >> a[i];

  const ll inf = 1e18;
  vector dp(n+1,vector(k+1,vector<ll>(2,-inf)));
  dp[0][0][0] = 0;
  rep(i,0,n) rep1(j,0,k) {
    chmax(dp[i+1][j][0],dp[i][j][0]);
    chmax(dp[i+1][j][0],dp[i][j][1]);

    if (j < k && dp[i][j][0] > -inf) {
      chmax(dp[i+1][j+1][1],dp[i][j][0]+a[i]);
    }
  }

  ll ans = max(dp[n][k][0],dp[n][k][1]);
  if (ans > -inf) cout << ans << endl;
  else cout << "Impossible" << endl;
}

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int t = 1;
  // cin >> t;
  for (int ti = 0; ti < t; ti++) solve();

  return 0;
}
0