# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
676294 |
2022-12-30T08:09:41 Z |
vjudge1 |
Schools (IZhO13_school) |
C++17 |
|
112 ms |
12996 KB |
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int32_t)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define left Kurumi_Tokisaki
#define right Kei_Karuizawa
#define next Mai_Sakurajima
#define div Yume_Irido
#define prev Chizuru_Mizuhara
#define cntbit(x) __builtin_popcountll(x)
#define MASK(x) ( 1ll << (x) )
#define Yes cout << "Yes"
#define YES cout << "YES"
#define No cout << "No"
#define NO cout << "NO"
#define AA cout << "Alice"
#define BB cout << "Bob"
/// TASK
/// -----------------------------
#ifdef LMQZZZ
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << " ]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[ in " <<__func__<< "() : line " <<__LINE__<< " ] : [ " << #x << " ] = [ "; _print(x); cerr << '\n';
#define TASK "C"
#else
#define deb(x...) 3326
#define TASK "lmqzzz"
#endif
///------------------------------
void lmqzzz();
void init() {};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
/// =================================
constexpr bool MULTITEST = 0;
/// ================================
init();
int32_t TT = 1;
if ( MULTITEST ) cin >> TT;
for(int32_t TTT = 1; TTT <= TT; TTT ++) {
lmqzzz();
// cout << '\n';
}
}
template <class T> inline T min(const T &a, const T &b, const T &c) { return min(a, min(b, c)); }
template <class T> inline T max(const T &a, const T &b, const T &c) { return max(a, max(b, c)); }
template <class T, class U> inline bool mini(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; }
template <class T, class U> inline bool maxi(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
constexpr int16_t dr[] = {0, 0, -1, 1};
constexpr int16_t dc[] = {1, -1, 0, 0};
constexpr int64_t MOD = 1e9 + 7;
constexpr int32_t MAXN = 1e6 + 10;
int n, a, b, x[MAXN], y[MAXN], id[MAXN];
int64_t ps[MAXN];
int64_t ss[MAXN];
void lmqzzz() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i ++) {
cin >> x[i] >> y[i];
id[i] = i;
}
/// x[i] + y[j] > x[j] + y[i]
/// x[i] - y[i] > x[j] - y[j]
sort(id + 1, id + n + 1, [](int i, int j) {
return x[i] - y[i] > x[j] - y[j];
});
priority_queue<int64_t> pq;
for (int i = 1; i <= n; i ++) {
ps[i] = ps[i - 1] + x[id[i]];
pq.ep(-x[id[i]]);
if (sz(pq) > a) {
ps[i] += pq.top();
pq.pop();
}
}
while (sz(pq)) pq.pop();
for (int i = n; i >= 1; i --) {
ss[i] = ss[i + 1] + y[id[i]];
pq.ep(-y[id[i]]);
if (sz(pq) > b) {
ss[i] += pq.top();
pq.pop();
}
}
int64_t res = 0;
for (int i = a; i <= n - b; i ++) {
res = max(res, ps[i] + ss[i + 1]);
}
cout << res;
}
Compilation message
school.cpp: In function 'int32_t main()':
school.cpp:72:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(TASK ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:73:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(TASK ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
14 ms |
2044 KB |
Output is correct |
14 |
Correct |
35 ms |
3536 KB |
Output is correct |
15 |
Correct |
52 ms |
6476 KB |
Output is correct |
16 |
Correct |
67 ms |
9032 KB |
Output is correct |
17 |
Correct |
84 ms |
9748 KB |
Output is correct |
18 |
Correct |
108 ms |
10572 KB |
Output is correct |
19 |
Correct |
109 ms |
11408 KB |
Output is correct |
20 |
Correct |
112 ms |
12996 KB |
Output is correct |