Submission #37169519
Source Code Expand
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#include <queue>
#ifdef MY_LOCAL
# include "helper.h"
#else
# define debug(...)
#endif
using ll = long long;
using pii = std::pair<int, int>;
constexpr int inf = 0x3f3f3f3f;
constexpr ll inf2 = 1LL * inf * inf;
constexpr int mod = 998244353;
constexpr int mod2 = 1e9 + 7;
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
multiset<int> all(a.begin(), a.begin() + m);
multiset<int> S;
for (int i = 0; i < m; ++i) {
S.insert(a[i]);
all.erase(all.find(a[i]));
if (S.size() > k) {
all.insert(*S.rbegin());
S.erase(S.find(*S.rbegin()));
}
}
assert(all.size() + S.size() == m);
ll tot = 0;
for (int x : S) tot += x;
cout << tot << ' ';
for (int i = m; i < n; ++i) {
int x = a[i - m];
all.insert(a[i]);
auto it = S.find(x);
if (it == S.end()) {
all.erase(all.find(x));
if (a[i] < *S.rbegin()) {
all.erase(all.find(a[i]));
all.insert(*S.rbegin());
tot -= *S.rbegin();
S.erase(S.find(*S.rbegin()));
S.insert(a[i]);
tot += a[i];
}
} else {
S.erase(S.find(x));
tot -= x;
tot += *all.begin();
S.insert(*all.begin());
all.erase(all.begin());
}
cout << tot << ' ';
assert(all.size() + S.size() == m);
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Least Elements |
| User | Unmei |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1959 Byte |
| Status | AC |
| Exec Time | 202 ms |
| Memory | 13324 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:45:22: warning: comparison of integer expressions of different signedness: ‘std::multiset<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
45 | if (S.size() > k) {
| ~~~~~~~~~^~~
In file included from /usr/include/c++/9/cassert:44,
from ./Main.cpp:5:
./Main.cpp:50:34: warning: comparison of integer expressions of different signedness: ‘std::multiset<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
50 | assert(all.size() + S.size() == m);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~
./Main.cpp:80:38: warning: comparison of integer expressions of different signedness: ‘std::multiset<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
80 | assert(all.size() + S.size() == m);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_example_00.txt, 00_example_01.txt |
| All | 00_example_00.txt, 00_example_01.txt, 01_max_00.txt, 01_max_01.txt, 02_min_00.txt, 03_m_small_00.txt, 04_random_00.txt, 04_random_01.txt, 04_random_02.txt, 04_random_03.txt, 04_random_04.txt, 04_random_05.txt, 04_random_06.txt, 04_random_07.txt, 04_random_08.txt, 04_random_09.txt, 04_random_10.txt, 04_random_11.txt, 04_random_12.txt, 04_random_13.txt, 04_random_14.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_example_00.txt | AC | 4 ms | 3444 KiB |
| 00_example_01.txt | AC | 2 ms | 3504 KiB |
| 01_max_00.txt | AC | 91 ms | 13324 KiB |
| 01_max_01.txt | AC | 188 ms | 8504 KiB |
| 02_min_00.txt | AC | 6 ms | 3460 KiB |
| 03_m_small_00.txt | AC | 52 ms | 3844 KiB |
| 04_random_00.txt | AC | 59 ms | 3600 KiB |
| 04_random_01.txt | AC | 122 ms | 5408 KiB |
| 04_random_02.txt | AC | 86 ms | 5536 KiB |
| 04_random_03.txt | AC | 112 ms | 4784 KiB |
| 04_random_04.txt | AC | 114 ms | 8744 KiB |
| 04_random_05.txt | AC | 116 ms | 6220 KiB |
| 04_random_06.txt | AC | 77 ms | 6772 KiB |
| 04_random_07.txt | AC | 202 ms | 11180 KiB |
| 04_random_08.txt | AC | 35 ms | 5084 KiB |
| 04_random_09.txt | AC | 16 ms | 4160 KiB |
| 04_random_10.txt | AC | 121 ms | 8812 KiB |
| 04_random_11.txt | AC | 59 ms | 5264 KiB |
| 04_random_12.txt | AC | 53 ms | 4144 KiB |
| 04_random_13.txt | AC | 63 ms | 4852 KiB |
| 04_random_14.txt | AC | 10 ms | 3564 KiB |