WA in STFOOD

I was solving Chef and Street Food
My code : https://ideone.com/jkGDga

Why is my code giving wrong output, can someone please help me?

  1. You ran the N loop twice, resulting in RE.
  2. It should be P[i] /(S[i]+1) instead of P[i] /(S[i])

Yes, I got your point. But my new code still doesn’t work, why?

You are declaring arrays inside the loop. Also you are calculating everything inside the loop. Put them outside.

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        int S[N], P[N], V[N];
        for (int i=0; i<N; i++){
                cin >> S[i] >> P[i] >> V[i];
            }
            int final[N];
            for (int i=0; i<N; i++){
                final[i] =(P[i]/(S[i]+1))* V[i];
            }
            cout << *max_element(final,final+N) << "\n";
        }
    return 0;
}

Yeah, you’re right, I got it ! I was a bit sleepy, so errors ought to happen… Thanks a lot and sorry for disturbing you.

1 Like