| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 545562 | Lobo | Cake 3 (JOI19_cake3) | C++17 | 353 ms | 980 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 4e3+10;
int n, m, c[maxn], v[maxn], ccval[maxn];
vector<int> vec[maxn];
void solve() {
cin >> n >> m;
vector<int> cc;
for(int i = 1; i <= n; i++) {
cin >> v[i] >> c[i];
cc.pb(c[i]);
}
sort(all(cc));
cc.erase(unique(all(cc)),cc.end());
for(int i = 1; i <= n; i++) {
int x = c[i];
c[i] = upper_bound(all(cc),c[i]) - cc.begin();
ccval[c[i]] = x;
vec[c[i]].pb(v[i]);
}
int ans = -inf;
for(int i = 1; i <= cc.size(); i++) {
multiset<int> st1,st2;
int sm = 0;
for(int j = i; j <= cc.size(); j++) {
for(auto x : vec[j]) {
st2.insert(x);
}
while(st1.size() < m && st2.size()) {
auto it = st2.end();
it--;
int x = *it;
st1.insert(x);
sm+= x;
st2.erase(st2.find(x));
}
while(st1.size() && st2.size()) {
auto it1 = st1.begin();
auto it2 = st2.end(); it2--;
if(*it1 >= *it2) break;
else {
sm+= *it2 - *it1;
int x = *it1;
int y = *it2;
st1.erase(st1.find(x));
st1.insert(y);
st2.erase(st2.find(y));
st2.insert(x);
}
}
if(st1.size() >= m) ans = max(ans, sm - 2*ccval[j] + 2*ccval[i]);
}
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
