9935 | 2024-03-19 08:42:53 | matyi | Maximális szorzat (50 pont) | cpp17 | Compilation error |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int szorzat (int a[],int n)
{
int szor=1;
for (int i=1;i<=n;i++)
{
szor*=a[i];
}
return szor;
}
int negativ (int a[],int n)
{
int db=0;
for (int i=1;i<=n;i++)
{
if (a[i]<0)
db++;
}
return db;
}
void rendez(int a[],int n)
{
bool felt=1;
int v=n-1,c;
while (felt)
{
felt=0;
for (int i=1;i<=v;i++)
{
if (a[i]<a[i+1])
{
c=a[i];
a[i]=a[i+1];
a[i+1]=c;
felt=1;
}
}
v--;
}
}
int main()
{
int n,k,b,a[100001];
//ifstream fin("be.in");
cin>>n>>k>>b;
int db;
for (int i=1;i<=n;i++)
{
cin>>a[i];
if (a[i]<0)
db++;
}
if (db<b)
{
cout<<-1;
}
else
{
int maxi=INT_MIN,poz;
if (negativ(a,n)>b)
{
int c=negativ(a,n)-b;
while (negativ(a,n)>b)
{
rendez(a,n);
int j=1;
while (a[j]>0 or j<n) j++;
while (j<=n and c!=0)
{
while (a[j]<1)
{
a[j]++;
k--;
}
c--;
j++;
}
}
}
while (k>0)
{
for (int i=1;i<=n;i++)
{
a[i]++;
if (szorzat(a,n)>maxi and negativ(a,n)<=b)
{
maxi=szorzat(a,n);
poz=i;
}
a[i]--;
}
a[poz]++;
k--;
}
cout<<maxi;
}
return 0;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:68:18: error: 'INT_MIN' was not declared in this scope
68 | int maxi=INT_MIN,poz;
| ^~~~~~~
main.cpp:4:1: note: 'INT_MIN' is defined in header '<climits>'; did you forget to '#include <climits>'?
3 | #include <algorithm>
+++ |+#include <climits>
4 |
main.cpp:101:21: error: 'poz' was not declared in this scope
101 | poz=i;
| ^~~
main.cpp:105:15: error: 'poz' was not declared in this scope
105 | a[poz]++;
| ^~~
Exited with error status 1