Submission #4398117
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2019/02/26 Problem: ABC 116 D / Link: http://abc116.contest.atcoder.jp/tasks/abc116_d ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
LL ans = 0LL;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
LL N, K; cin >> N >> K;
VL t(N), d(N);
FOR(i, 0, N) {
cin >> t[i] >> d[i];
t[i]--;
}
VI index(N, 0);
iota(ALL(index), 0);
sort(ALL(index),
[&](int a, int b) {
return d[a] > d[b];
});
VI used(N, 0);
LL sum = 0;
LL typecnt = 0;
priority_queue<LL,VL,greater<LL>>pq;
FOR(i, 0, K) {
int idx = index[i];
sum += d[idx];
if (used[t[idx]]) {
pq.push(d[idx]);
}
else {
used[t[idx]] = 1;
typecnt++;
}
}
ans = sum + typecnt * typecnt;
DD(de(ans, sum, typecnt));
FOR(i, K, N) {
int idx = index[i];
if (used[t[idx]]) {
continue;
}
if (SZ(pq)) {
LL swapval = pq.top(); pq.pop();
DD(de(swapval));
used[t[idx]] = 1;
typecnt++;
sum = sum - swapval + d[idx];
DD(de(sum))
ans = max(ans, sum+typecnt*typecnt);
}
}
cout << ans << "\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Various Sushi |
| User |
Yang33 |
| Language |
C++14 (GCC 5.4.1) |
| Score |
400 |
| Code Size |
2145 Byte |
| Status |
AC |
| Exec Time |
31 ms |
| Memory |
3324 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
s1.txt, s2.txt, s3.txt |
| All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, s1.txt, s2.txt, s3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01.txt |
AC |
1 ms |
256 KiB |
| 02.txt |
AC |
1 ms |
256 KiB |
| 03.txt |
AC |
1 ms |
256 KiB |
| 04.txt |
AC |
1 ms |
256 KiB |
| 05.txt |
AC |
1 ms |
256 KiB |
| 06.txt |
AC |
1 ms |
256 KiB |
| 07.txt |
AC |
1 ms |
256 KiB |
| 08.txt |
AC |
1 ms |
256 KiB |
| 09.txt |
AC |
1 ms |
256 KiB |
| 10.txt |
AC |
1 ms |
256 KiB |
| 11.txt |
AC |
1 ms |
256 KiB |
| 12.txt |
AC |
1 ms |
256 KiB |
| 13.txt |
AC |
1 ms |
256 KiB |
| 14.txt |
AC |
6 ms |
1408 KiB |
| 15.txt |
AC |
18 ms |
2560 KiB |
| 16.txt |
AC |
11 ms |
1152 KiB |
| 17.txt |
AC |
20 ms |
1920 KiB |
| 18.txt |
AC |
2 ms |
384 KiB |
| 19.txt |
AC |
26 ms |
2432 KiB |
| 20.txt |
AC |
16 ms |
3068 KiB |
| 21.txt |
AC |
21 ms |
2688 KiB |
| 22.txt |
AC |
29 ms |
2688 KiB |
| 23.txt |
AC |
29 ms |
2688 KiB |
| 24.txt |
AC |
29 ms |
2688 KiB |
| 25.txt |
AC |
29 ms |
2816 KiB |
| 26.txt |
AC |
30 ms |
2944 KiB |
| 27.txt |
AC |
29 ms |
2688 KiB |
| 28.txt |
AC |
31 ms |
3324 KiB |
| 29.txt |
AC |
28 ms |
2688 KiB |
| 30.txt |
AC |
31 ms |
2944 KiB |
| 31.txt |
AC |
16 ms |
2560 KiB |
| 32.txt |
AC |
21 ms |
2560 KiB |
| 33.txt |
AC |
24 ms |
2560 KiB |
| 34.txt |
AC |
26 ms |
2560 KiB |
| 35.txt |
AC |
28 ms |
3068 KiB |
| 36.txt |
AC |
30 ms |
3196 KiB |
| 37.txt |
AC |
27 ms |
2432 KiB |
| 38.txt |
AC |
26 ms |
2432 KiB |
| s1.txt |
AC |
1 ms |
256 KiB |
| s2.txt |
AC |
1 ms |
256 KiB |
| s3.txt |
AC |
1 ms |
256 KiB |