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?
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?
You are declaring arrays inside the loop. Also you are calculating everything inside the loop. Put them outside.
#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.