This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include "holiday.h"
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 1e5 + 15;
int a[N];
inline ll get(int l, int r, int d) {
vector <int> now = {};
for(int j = l; j <= r; ++j)
now.pb(a[j]);
sort(now.rbegin(), now.rend());
int num = d - (r - l);
if(num <= 0)
return 0;
ll sum = 0;
for(int k = 0; k < min((int)now.size(), num); ++k)
sum += now[k];
return sum;
}
long long findMaxAttraction(int n, int start, int d, int attraction[]) {
for(int i = 0; i < n; ++i)
a[i] = attraction[i];
ll ans = 0;
for(int i = start; i < n; ++i) {
Max(ans, get(start, i, d));
vector <int> now = {};
for(int j = start; j <= i; ++j)
now.pb(a[j]);
for(int j = start - 1; j >= 0; --j) {
now.pb(a[j]);
sort(now.rbegin(), now.rend());
int num = d - (i - j) - (i - start);
if(num <= 0)
break;
ll sum = 0;
for(int k = 0; k < min((int)now.size(), num); ++k)
sum += now[k];
Max(ans, sum);
}
}
return ans;
}
# | 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... |