이 제출은 이전 버전의 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 = 2e3+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 <= n; i++) {
multiset<int> st1,st2;
int sm = 0;
for(int j = i; j <= n; j++) {
for(auto x : vec[j]) {
st2.insert(x);
}
while(st1.size() < m && st2.size()) {
auto it = st2.end();
it--;
st1.insert(*it);
sm+= *it;
st2.erase(it);
}
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;
st1.erase(it1);
st1.insert(*it2);
st2.erase(it2);
st2.insert(x);
}
}
if(st1.size() >= m) ans = max(ans, sm - 2*ccval[j] + 2*ccval[i]);
// cout << ccval[i] << " " << ccval[j] << " " << sm << endl;
}
}
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;
int t = 1;
while(tt--) {
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'void solve()':
cake3.cpp:47:30: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
47 | while(st1.size() < m && st2.size()) {
| ~~~~~~~~~~~^~~
cake3.cpp:70:27: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
70 | if(st1.size() >= m) ans = max(ans, sm - 2*ccval[j] + 2*ccval[i]);
| ~~~~~~~~~~~^~~~
cake3.cpp: In function 'int32_t main()':
cake3.cpp:88:9: warning: unused variable 't' [-Wunused-variable]
88 | int t = 1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |