이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n) - 1; i >= 0; --i)
#define rrep2(i, n, t) for(ll i = ll(n) - 1; i >= ll(t); --i)
#define pb push_back
#define eb emplace_back
#define SZ(a) int(a.size())
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
vl get_max(const vi &v, int d, int s) {
int n = SZ(v);
vl res(d + 1);
if (!n) return res;
// vvl ls(n, vl(n + 1));
multiset<int> st;
rep(i, n) {
st.insert(v[i]);
auto it = st.end();
ll sum = 0;
rep(j, i + 1) {
--it;
sum += *it;
int now = s * (i + 1) + j + 1;
if (now > d) break;
chmax(res[now], sum);
// ls[i][j + 1] = ls[i][j] + *it;
}
}
// auto f = [&](int i, int num) -> ll {
// assert(0 <= i and i < n);
// assert(0 <= num);
// return ls[i][min(num, i + 1)];
// };
// int now = 0;
// rep2(i, s, d + 1) {
// rep(j, n) {
// if (s * (j + 1) > i) break;
// chmax(res[i], f(j, i - s * (j + 1)));
// }
// res[i] = f(now, i - s * (now + 1));
// while (now + 1 < n and s * (now + 2) <= i) {
// ll l = f(now + 1, i - s * (now + 2));
// if (chmax(res[i], l)) ++now;
// else break;
// }
// }
return res;
}
ll findMaxAttraction(int n, int start, int d, int attraction[]) {
if (n > 3000) {
ll ans = 0;
vi cnt(101);
rep(i, n) {
if (!d) break;
++cnt[attraction[i]];
ll sum = 0, rem = d;
rrep(j, 101) {
if (cnt[j] < rem) {
rem -= cnt[j];
sum += j * cnt[j];
} else {
sum += j * rem;
break;
}
}
chmax(ans, sum);
--d;
}
return ans;
}
vi l, r;
rrep(i, start) l.pb(attraction[i]);
rep2(i, start + 1, n) r.pb(attraction[i]);
ll ans = 0;
rep(_, 2) {
vl x = get_max(l, d, 1);
vl y = get_max(r, d, 2);
rep(i, d + 1) chmax(ans, x[i] + y[d - i]);
rep(i, d) chmax(ans, x[i] + y[d - 1 - i] + attraction[start]);
swap(l, r);
}
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... |