이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author : Lăng Trọng Đạt
* created: 2024-08-25
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int i = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int g[N];
int n, m, k, a, b;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
cin >> n >> m;
vector<pii> p(n);
for (auto&[c, v] : p) cin >> v >> c;
sort(all(p));
int ans = -INF;
db(p)
FOR(i, 0, n - 1) {
db(p[i])
if (i + m > n) break;
int total = p[i].se;
multiset<int> val;
for (int j = i + 1; j < i + m - 1; j++) {
val.insert(p[j].se);
total += p[j].se;
}
db(i, i + m -1)
db(val, total)
for (int j = i + m - 1; j < n; j++) {
val.insert(p[j].se);
total += p[j].se;
mx(ans, total - 2*(p[j].f - p[i].f));
db(j, total, p[j], ans)
total -= *val.begin();
val.erase(val.begin());
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'int32_t main()':
cake3.cpp:38:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
38 | for (auto&[c, v] : p) cin >> v >> c;
| ^
cake3.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen("hi.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |