이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef local
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : "\033[0m)\n")));
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define sort_uni(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
using ll = int64_t;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1e18;
const int maxn = 500025, inf = 1e9;
pair<int,int> v[maxn];
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> v[i].second >> v[i].first;
sort(v, v+n);
k -= 2;
ll ans = -INF;
for (int i = 0; i < n; i++) {
priority_queue<int, vector<int>, greater<int>> pq;
ll sum = 0;
for (int j = i+1; j < n; j++) {
if (pq.size() == k)
ans = max(ans, sum + v[i].second + v[j].second - (v[j].first - v[i].first) * 2);
sum += v[j].second, pq.push(v[j].second);
if (pq.size() > k) sum -= pq.top(), pq.pop();
}
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'int main()':
cake3.cpp:37:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if (pq.size() == k)
| ~~~~~~~~~~^~~~
cake3.cpp:40:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (pq.size() > k) sum -= pq.top(), pq.pop();
| ~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |