forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.cpp
61 lines (51 loc) · 1.22 KB
/
sound.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <vector>
#include <deque>
#include <map>
using namespace std;
int main() {
int n, length, variance;
cin >> n >> length >> variance;
vector<int> v(n);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
map<int, int> used;
deque<int> current;
for(int i = 0; i < length-1; i++) {
// Add element
int element = v[i];
used[element]++;
current.push_back(element);
}
bool printed = false;
for(int i = length-1; i < n; i++) {
// Add element
int element = v[i];
used[element]++;
current.push_back(element);
/*
cout << "Line: ";
for(auto j : current) {
cout << j << " ";
}
cout << endl;
*/
// Process
int hi = used.rbegin()->first;
int lo = used.begin()->first;
if(hi - lo <= variance) {
printed = true;
cout << i-length+2 << endl;
}
// Remove element after use
used[current.front()]--;
if(used[current.front()] == 0) {
used.erase(current.front());
}
current.pop_front();
}
if(!printed) {
cout << "NONE" << endl;
}
}