Skip to content

Instantly share code, notes, and snippets.

@uhmseohun
Created August 9, 2020 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhmseohun/444407694d43898631f0f8f4b704763e to your computer and use it in GitHub Desktop.
Save uhmseohun/444407694d43898631f0f8f4b704763e to your computer and use it in GitHub Desktop.
#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