This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// tree bends in youth
/// 1.10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =2e5 + 5;
const ll NN = 2e5;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
ll a[15];
vector <ll> v;
vector <ll> p;
bool used[15];
ll n,k,ans,res;
void per(ll i){
if(i == k + 1){
if(res >ans){
ans = res;
p.clear();
for(ll to : v)p.pb(to);
}
}
else{
for(ll j = 1;j <= n;j++){
if(used[j] == 0){
ll z = 0,x = 0;
for(ll g = j;g > 0;g--){
if(used[g] == 1)break;
z += a[g];
}
for(ll g = j + 1;g <= n;g++){
x += a[g];
if(used[g] == 1)break;
}
res += (x * z);
used[j] = 1;
v.pb(j);
per(i + 1);
v.pop_back();
used[j] = 0;
res -= (x * z);
}
}
}
}
void solve(){
cin >> n >> k;
for(ll i = 1;i <= n;i++)cin >> a[i];
per(1);
cout << ans << '\n';
for(ll to : p){
cout<<to << ' ';
}
}
main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("moocrypt.in","r",stdin);
// freopen("moocrypt.out","w",stdout);
ll abdu= 1;
// cin >> abdu;
for(ll i = 1;i <= abdu;i++){
// cout << "Case " << i << ": ";
solve();
}
}
Compilation message (stderr)
sequence.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
64 | main (){
| ^~~~
# | 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... |