给定n个整数,从中删除k个数字,然后使得剩下的数字乘积最大
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 100010, mod = 1000000009;
int a[N];
int main()
{
int n, k;
cin >> n >> k;
for (int i = 0;i < n;i++)
{
scanf("%d", &a[i]);
}
sort(a, a + n);
LL Numreturn = 1;
int l = 0, r = n - 1;
int sign = 1;
if (k % 2)
{
Numreturn = a[r];
r--;
k--;
if (Numreturn < 0)
sign = -1;
}
while (k)
{
LL x = (LL)a[l] * a[l + 1], y = (LL)a[r] * a[r - 1];
if (x * sign > y * sign)
{
Numreturn = x % mod * Numreturn % mod;
l += 2;
}
else
{
Numreturn = y % mod * res % mod;
r -= 2;
}
k -= 2;
}
cout << Numreturn << endl;
return 0;
}