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 <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];
multiset <int> now;
inline ll get(int num) {
if(num <= 0)
return 0;
ll sum = 0;
multiset <int>::reverse_iterator it = now.rbegin();
for(int cnt = 0; it != now.rend() && cnt < num; ++it, ++cnt)
sum += *it;
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) {
now.insert(a[i]);
Max(ans, get(d - (i - start)));
for(int j = start - 1; j >= 0; --j) {
now.insert(a[j]);
Max(ans, get(d - (i - j) - (i - start)));
}
for(int j = start - 1; j >= 0; --j)
now.erase(now.find(a[j]));
}
now.clear();
reverse(a, a + n);
start = n - start - 1;
for(int i = start; i < n; ++i) {
now.insert(a[i]);
Max(ans, get(d - (i - start)));
for(int j = start - 1; j >= 0; --j) {
now.insert(a[j]);
Max(ans, get(d - (i - j) - (i - start)));
}
for(int j = start - 1; j >= 0; --j)
now.erase(now.find(a[j]));
}
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... |