Created
August 9, 2020 08:12
-
-
Save uhmseohun/444407694d43898631f0f8f4b704763e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <set> | |
using namespace std; | |
const int _size = 100005; | |
int n, k, m[_size]; | |
multiset<int> s; | |
int get_minmax(multiset<int> s) { | |
return (*s.begin()) * (*s.rbegin()); | |
} | |
int main() { | |
scanf("%d %d", &n, &k); | |
for(int i=0; i<n; ++i) { | |
scanf("%d", &m[i]); | |
} | |
for(int i=0; i<k; ++i) { | |
s.insert(m[i]); | |
} | |
int ans = get_minmax(s); | |
for(int i=k; i<n; ++i) { | |
auto out = s.find(m[i-1]); | |
s.erase(out, out); | |
s.insert(m[i]); | |
ans = max(ans, get_minmax(s)); | |
} | |
printf("%d\n", ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment