이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <llint, llint> pi;
const int MAXN = 200005;
const llint INF = 1000000000000000000LL;
llint n, m, sum, sol = -INF;
pi p[MAXN];
multiset <llint> st;
vector <int> v;
bool cmp (pi a, pi b) {
return a.second < b.second;
}
void init () {
st.clear();
sum = 0;
}
void ubaci (llint val) {
st.insert(val);
sum += val;
if (st.size() > m - 2) {
sum -= *st.begin();
st.erase(st.begin());
}
}
llint calc (int j) {
init();
llint res = -INF;
int ind = -1;
for (int i = j - 1; i >= 0; i--) {
if (st.size() == m - 2) {
llint tmp = sum + p[i].first + p[i].second;
if (tmp > res) {
res = tmp;
ind = i;
}
}
ubaci(p[i].first);
}
//cout << "bla " << ind << " " << j << " " << res << endl;
v.push_back(ind);
return res;
}
bool check () {
for (int i = 1; i < v.size(); i++) {
if (v[i] < v[i - 1]) return 0;
}
return 1;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
p[i].second *= 2;
}
sort(p, p + n, cmp);
for (int j = m - 1; j < n; j++) {
sol = max(sol, calc(j) + p[j].first - p[j].second);
}
cout << sol;
if (!check()) cout << "RIP";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'void ubaci(llint)':
cake3.cpp:28:19: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'llint' {aka 'long long int'} [-Wsign-compare]
28 | if (st.size() > m - 2) {
| ~~~~~~~~~~^~~~~~~
cake3.cpp: In function 'llint calc(int)':
cake3.cpp:39:23: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'llint' {aka 'long long int'} [-Wsign-compare]
39 | if (st.size() == m - 2) {
| ~~~~~~~~~~^~~~~~~~
cake3.cpp: In function 'bool check()':
cake3.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |