this is my code for the TLG problem
it is showing wrong answer after submitting
please review it
try:
t=int(input())
score=[]
for i in range(t):
p1,p2=[int(x) for x in input().split()]
if p1>p2:
lead=p1-p2
w=1
score.append([w,lead])
else:
lead=p2-p1
w=2
score.append([w,lead])
score.sort(key=lambda x: x[1])
print(score[t-1][0],abs(score[t-1][1]))
except:
pass
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;cin>>t;
vector<vector> a(t);
for(int i=0;i<t;i++){
int x,y;cin>>x>>y;
a[i].push_back(x);
a[i].push_back(y);
}
vector<vector<int>> b(t);
for(int i=0;i<t;i++){
int k=abs(a[i][0]-a[i][1]);
b[i].push_back(k);
if(a[i][0]>a[i][1]){
b[i].push_back(1);
}
else{
b[i].push_back(2);
}
}
sort(b.begin(),b.end(),[&](vector<int> &a,vector<int> &b){
return a[0]>b[0];
});
cout<<b[0][1]<<" "<<b[0][0]<<endl;
return 0;
}
what is the problem in above code?
What is wrong with this?
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int N{},Si{0},Ti{0};
cin>>N;
int max{0},player{0};
while(N--)
{
cin>>Si>>Ti;
if(abs(Si-Ti)>max)
{
max=abs(Si-Ti);
Si>Ti?player=1:player=2;
}
}
cout<<player<<" "<<max;
return 0;
}
Why my code is wrong? It is showing proper output for most inputs
#include
#include
using namespace std;
int main() {
int n;
cin >> n;
int s[n], t[n], fir[n], sec[n];
for(int i=0;i<n;i++)
cin>>s[i]>>t[i];
for(int i=0;i<n;i++)
{
if(s[i]>t[i])
{fir[i]=s[i]-t[i]; sec[i]=0;}
else
{sec[i]=t[i]-s[i]; fir[i]=0;}
}
if(*max_element(fir,fir+n)>*max_element(sec,sec+n))
{cout<<"1 "; cout<<*max_element(fir,fir+n);}
else
cout<<"2 "<<*max_element(sec,sec+n);
}
where’s the problem ???
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int p1[t],p2[t],res,k=0,flag=0,i;
for( i = 0 ; i<t ; ++i) cin>>p1[i]>>p2[i];
for( i = 0 ; i<t ; ++i)
{
res = abs(p1[i]-p2[i]);
if(res>=k)
{
k=res;
flag = i ;
}
}
int s = (p1[flag]>p2[flag]) ? 1 : 2 ;
cout<<s<<" "<<k;
return 0;
}
I think we don’t need arrays for this problem. Java solution :-
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int cummulativeScorePlayer1 = 0;
int cummulativeScorePlayer2 = 0;
int lead = 0;
int max = Integer.MIN_VALUE;
int playerWon = 0;
while(T-- > 0){
int score1 = sc.nextInt();
int score2 = sc.nextInt();
cummulativeScorePlayer1 = cummulativeScorePlayer1 + score1;
cummulativeScorePlayer2 = cummulativeScorePlayer2 + score2;
if(cummulativeScorePlayer1 > cummulativeScorePlayer2){
lead = cummulativeScorePlayer1 - cummulativeScorePlayer2;
if(lead > max){
max = lead;
playerWon = 1;
}
}
else if(cummulativeScorePlayer2 > cummulativeScorePlayer1){
lead = cummulativeScorePlayer2 - cummulativeScorePlayer1;
if(lead > max){
max = lead;
playerWon = 2;
}
}
}
System.out.println(playerWon+" "+max);
can somebody explain whats wrong with my code ?
n=int(input())
a1=[]
b1=[]
g=1
h=2
x=0
y=0
for i in range(n):
a,b= map(int,input().split())
#x ,y = map(int, input().split())
a=x+a
b=y+b
if (a>b):
a1.append((a-b))
else:
b1.append((b-a))
x=a
y=b
a1.sort()
b1.sort()
if (a1[-1]>b1[-1]):
print(g,a1[-1])
else:
print([h,b1[-1]])
All code is right and manually giving write answer but during compiling getting error
Plz anyone have a look on my code and help if you can
Problem Link:- Solution: 49831330 | CodeChef
I have used Array method in c# and most of the test cases are right. CodeChef is saying wrong answer .
I wanna know whats the mistake … let me know…
[CodeChef: Practical coding for everyone ](https://My code)
#include
using namespace std;
int main() {
int round,maxi=0,i,n;
cin>>round;
int p1[round],p2[round],result[round],player[round];
for(i=0;i<round;i++)
{
cin>>p1[i]>>p2[i];
if(p1[i]<p2[i]){
result[i]=p2[i]-p1[i];player[i]=2;}
else{
result[i]=p1[i]-p2[i];player[i]=1;}
if(result[i]>maxi){
maxi=result[i];n=player[i];}
}
cout<<n<<" "<<maxi<<endl;
return 0;
}
can anybody help me with this?..why this code is not acceptable
yadhukp
October 31, 2021, 7:28am
189
Hi guys ,
can anyone tell me what’s wrong with my code, I gave multiple inputs and all shows correct answer but when I submit is says wrong.
her is my code
https://www.codechef.com/viewsolution/53337328
thanks in advance
whats wrong with this solution??
#include<bits/stdc++.h>
using namespace std;
int main(){
// freopen("input.txt", "r", stdin);
int n;
cin>>n;
int a, b ;
int amax=-1 , bmax=-1;
for(int i=0;i<n;i++){
cin>>a>>b;
if( a > b){
amax = max(amax, a-b);
}
else{
bmax = max(bmax, b-a);
}
}
if( amax > bmax){
cout<<1<<" "<<amax<<endl;
}
else{
cout<<2<<" "<<bmax<<endl;
}
return 0;
}