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 <bits/stdc++.h>
#define FOR(var,bound) for(int var = 0; var < bound; var++)
#define FORB(var,lb,ub) for (int var = lb; var < ub; var++)
#define FORR(var,bound) for(int var = bound-1; var >= 0; var--)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
set<int> included;
set<int> excluded;
long long sum = 0;
long long res = 0;
for (int i = 0; i < min(d + 1, n); i++) {
excluded.insert(attraction[i]);
int canTake = d - i;
while (included.size() > canTake) {
auto it = included.begin();
excluded.insert(*it);
sum -= *it;
included.erase(it);
}
while (included.size() < canTake && excluded.size()) {
auto it = (--excluded.end());
included.insert(*it);
sum += *it;
excluded.erase(*it);
}
while (included.size() && excluded.size() && *included.begin() < *(--excluded.end())) {
included.insert(*excluded.rbegin());
sum += *excluded.rbegin();
excluded.insert(*included.begin());
sum -= *included.begin();
included.erase(included.begin());
excluded.erase(--excluded.end());
}
res = max(sum, res);
}
return res;
}
#ifdef LOCAL_TEST
namespace hidden {
int attraction[1000000];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, start, d;
cin >> n >> start >> d;
FOR(i, n) {
cin >> hidden::attraction[i];
}
cout << findMaxAttraction(n, start, d, hidden::attraction) << endl;
}
#endif
Compilation message (stderr)
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:25:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | while (included.size() > canTake) {
| ~~~~~~~~~~~~~~~~^~~~~~~~~
holiday.cpp:32:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
32 | while (included.size() < canTake && excluded.size()) {
| ~~~~~~~~~~~~~~~~^~~~~~~~~
# | 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... |