이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Muallif: Azimjon Mehmonali o'g'li
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;
const int N = 111111;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
vector<vector<pair<int, int>>> g;
g.push_back(a);
int jv = 0;
vector<int> el;
while (k--) {
int ka, ki;
ka = -INF;
ki = -1;
for (auto v : g) {
int yi = 0;
for (auto [x, y] : v)
yi += x;
int hy = 0;
for (int i = 0; i < (int)v.size(); i++) {
hy += v[i].first;
if (hy * (yi - hy) > ka) {
ka = hy * (yi - hy);
ki = v[i].second;
}
}
}
jv += ka;
el.push_back(ki);
int oc;
vector<pair<int, int>> qq, ww;
for (int j = 0; j < (int)g.size(); j++) {
auto v = g[j];
int ii = -1;
for (int i = 0; i < (int)v.size(); i++) {
if (ki == v[i].second) {
ii = i;
}
}
if (ii != -1) {
vector<pair<int, int>> tr;
for (int i = 0; i <= ii; i++) {
qq.push_back(v[i]);
}
g.push_back(tr);
for (int i = ii + 1; i < (int)v.size(); i++) {
ww.push_back(v[i]);
}
oc = j;
break;
}
}
g.push_back(qq);
g.push_back(ww);
g.erase(g.begin() + oc);
}
cout << jv << endl;
for (int i : el) {
cout << i + 1 << " ";
}
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... |