이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll Mod = 1e9 + 7;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
//const ll N = 1ll << Log;
const int Maxn = 1e5;
const int Base = 101;
typedef pair<pll, ll> node;
ll a[Maxn], mk[Maxn];
ll ps[Maxn], sf[Maxn];
vector<ll> A;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, k;
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];
ll ans = 0;
mk[0] = 1;
mk[n] = 1;
for(int j = 0; j < k; j++){
ps[0] = 0;
for(int i = 1; i <= n; i++) ps[i] = (mk[i] ? 0 : ps[i - 1] + a[i - 1]);
sf[n] = 0;
for(int i = n - 1; i >= 0; i--) sf[i] = (mk[i] ? 0 : sf[i + 1] + a[i]);
ll mx = -1;
ll ind = 0;
for(int i = 0; i <= n; i++){
if(mk[i]) continue;
if(ps[i] * sf[i] > mx){
mx = ps[i] * sf[i];
ind = i;
}
}
ans += mx;
mk[ind] = 1;
A.pb(ind);
}
cout << ans << '\n';
sort(all(A));
for(auto x : A) cout << x << ' ';
cout << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |