Submission #3611312
Source Code Expand
#include <deque>
#include <iostream>
using namespace std;
const int N = 1e5;
int a[N + 1];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
a[n] = 0;
++n;
int water = 0;
int last = 0;
deque<int> q;
long long res = 0;
for (int u = 0; u < n; ++u) {
while (!q.empty() && q.front() < u) {
q.pop_front();
}
while (water < k) {
while (last <= u + water && last < n) {
while (!q.empty() && a[last] <= a[q.back()]) {
q.pop_back();
}
q.push_back(last);
++last;
}
res += a[q.front()];
++water;
}
--water;
}
cout << res << '\n';
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Tough Journey |
| User | dnk |
| Language | C++14 (GCC 5.4.1) |
| Score | 600 |
| Code Size | 729 Byte |
| Status | AC |
| Exec Time | 39 ms |
| Memory | 640 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | big_01.txt, big_02.txt, big_03.txt, big_04.txt, big_05.txt, sample_01.txt, sample_02.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt, small_05.txt, small_06.txt, small_07.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| big_01.txt | AC | 35 ms | 640 KiB |
| big_02.txt | AC | 33 ms | 640 KiB |
| big_03.txt | AC | 39 ms | 640 KiB |
| big_04.txt | AC | 39 ms | 640 KiB |
| big_05.txt | AC | 38 ms | 640 KiB |
| sample_01.txt | AC | 1 ms | 256 KiB |
| sample_02.txt | AC | 1 ms | 256 KiB |
| small_01.txt | AC | 1 ms | 256 KiB |
| small_02.txt | AC | 1 ms | 256 KiB |
| small_03.txt | AC | 1 ms | 256 KiB |
| small_04.txt | AC | 1 ms | 256 KiB |
| small_05.txt | AC | 1 ms | 256 KiB |
| small_06.txt | AC | 1 ms | 256 KiB |
| small_07.txt | AC | 1 ms | 256 KiB |