| 18926 | 2025-11-12 17:44:48 | Kristóf | Maximális szorzat (50 pont) | cpp17 | Forditási hiba |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
long long mod=1000000007;
int main()
{
int n,k,b;
cin>>n>>k>>b;
priority_queue<int> negativ,poz;
int x;
for(int i=0;i<n;i++)
{
cin>>x;
if(x>-1)
{
poz.push(x*-1);
}
else
{
negativ.push(x);
}
}
if(negativ.size()<b)
{
cout<<-1;
return 0;
}
if(negativ.size() == b && n!=b)
{
while(k--)
{
x=poz.top()*-1;poz.pop();
poz.push((x+1) % mod)*-1);
}
}
else if(negativ.size() > b)
{
while(negativ.size()!=b && negativ.size()>0)
{
k+=negativ.top();
if(k<0)
{
cout<<-1;
return 0;
}
poz.push(0);
negativ.pop();
}
while(k-- && !poz.empty())
{
x=poz.top()*-1;poz.pop();
poz.push(((x+1)%mod)*-1);
}
}
else
{
while(k-- && negativ.top()!=-1)
{
x=negativ.top();
x++;
negativ.push(x);
negativ.pop();
}
if(negativ.top() == -1 && k>0)
{
cout<<-1;
return 0;
}
}
long long ans=1;
while(!poz.empty())
{
ans = (ans * (-poz.top() % mod)) % mod;
poz.pop();
}
while(!negativ.empty())
{
ans = (ans * (abs(negativ.top()) % mod)) % mod;
negativ.pop();
}
cout<<ans;
return 0;
}
open /var/local/lib/isolate/433/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:37:34: error: invalid operands of types 'void' and 'int' to binary 'operator*'
37 | poz.push((x+1) % mod)*-1);
| ~~~~~~~~~~~~~~~~~~~~~^~~
| | |
| void int