# Help required in chef and proxy

my solution to the problem https://www.codechef.com/JUNE19B/problems/PROXYC/ is
https://ideone.com/nqh9Qq even after passing almost all the manually created test cases. i got wa. anyone please help me with whats wrong in my code?

I might be wrong but it think your logic is wrong, also you should add brackets to keep precedence and associativity intact…lots of bracket issues in your code

1 Like

your solution is too complex ,but still this solution can work with a few changes

Line 28 : your always adding 1 to the required no of proxies. That is a wrong idea. You have to add 1 only when the total attendance is not divisible by 4. That is let’s assume that you have total no of days equal to 8. then required_attendance = 8 * 0.75 = 6 and not 8 * 0.75 + 1 = 7. This is the logic used there.

Even the variable prox is bit confusing in the for loop. If you already know how many proxy you need then the better option is decrementing the req variable which is the nod of required proxy in your program. If it doesn’t shoots to zero then the condition for the requirement is just fired up else print -1.

https://ideone.com/e.js/z1Uz29

this is link to my solution its very very basic and simple. take a look and then follow up

1 Like

hello!
i am facing some issues in code of chef and proxy.
my code is below:

``````#include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t - - )
{
double n;
string s;
cin>>n>>s;
double p=0,need=0,a=0;
for(int i=0;i<n;i++)
{
if(s[i]=='P')p++;
}

while((p/n)<0.75)
{
p++;
need++;
}
int g=need;
//cout<<p/n<<endl;
//cout<<g<<endl;
for(int i=2;i<n-2 && need!=0;i++)
{
if(s[i]=='A')
{
if((s[i-1]=='P' || s[i-2]=='P') && (s[i+1]=='P' || s[i+2]=='P'))
{
s[i]='P';
need--;

}
}
}
if(need!=0)cout<<"-1"<<endl;
else cout<<g<<endl;

}

}'''``````

2 Likes

Try :

``````1
7
PAAAPPP
``````

The correct answer I believe is `-1`

PAAAPPP here A at index 2(index begins with 0) can be converted to P and also index 3.