← Back to topics
Topic

z-donalds...I don't get it or...?

d
dancsi
please help me with this:
#include <iostream>
#include <math.h>

using namespace std;
double a[2000];
int m;
double u1(int i, int l)
{
double ret=0;
for(int j=0;j<l;j++)
{
ret+=a[i+j]-floor(a[i+j]);
}
return ret;
}
double u2(int i, int l)
{
double ret=0;
for(int j=0;j<l;j++)
{
ret+=floor(a[i+j])+1-a[i+j];
}
return ret;
}
int main()
{
int n, i;
double zarada=0, rep;
scanf("%d%d", &n, &m);
for(i=0;i<n;i++)
{
scanf("%lf", &a[i]);
}
i=n-n%m-1;
rep=max(u1(i, n%m), u2(i, n%m));
for(i=0;i<=n-m-1;i+=m)
{
zarada+=max(u1(i,m), u2(i,m));
}
zarada+=rep;
zarada*=100;
printf("%.0lf", zarada);
return 0;
}
s
syntax_error
your program doesn't produce correct output for any of the given test cases, so it's obviously wrong. i'm not quite sure what you're trying to do here, but it looks like a greedy approach, and what the problem asks from you is an optimal solution,