#include
using namespace std;
int k;
int modulus1(int a)
{
if(a>0)
k=a;
else
k=-a;
return k;
}
int main()
{
int i,rounds,j,q,l,s;
cin>>rounds;
int playerone[rounds];//stores scores of player one in each round
int playertwo[rounds];//stores scores of player two in each round
int lead[rounds];//stores lead of player one over player 2
int moduluslead[rounds];//stores modulus of lead
s=0;
for(i=0;i<rounds;i++)
{
cin>>playerone[i];
cin>>playertwo[i];
s=s+playerone[i]-playertwo[i];
lead[i]=s;
moduluslead[i]=modulus1(lead[i]);
}
j=moduluslead[0];
q=0;
for(i = 1;i<rounds; i++)//loop to find modulus of maximum lead
{
if(moduluslead[i]>j)
{
j=moduluslead[i];
q=i;
}
}
l=2;
if (lead[q]>0)
l=1;
using namespace std;
int main() {
int n, a, b, max, player;
cin >> n;
if (n == 0)
{
cout << 0 << " " << 0 << “\n”;
}
else
{
int** p;
p = new int*[n];
for (int i = 0; i < n; i++)
{
p[i] = new int[2];
}
int** win;
win = new int*[n];
for (int i = 0; i < n; i++)
{
win[i] = new int[2];
}
for (int i = 0; i < n; i++)
{
cin >> a >> b;
if ( i == 0)
{
p[i][0] = a;
p[i][1] = b;
}
else
{
p[i][0] = p[i-1][0] + a;
p[i][1] = p[i-1][1] + b;
}
}
for (int i = 0; i < n; i++)
{
if (p[i][0] > p[i][1])
{
win[i][0] = 1;
int x = p[i][0] - p[i][1];
win[i][1] = x;
}
else
{
win[i][0] = 2;
int x = p[i][1] - p[i][0];
win[i][1] = x;
}
}
for (int i = 0; i < n; i++)
{
max = win[0][1];
if (win[i][1] > max)
{
max = win[i][1];
}
}
for (int i = 0; i < n; i++)
{
if (win[i][1] == max)
{
player = win[i][0];
}
}
cout << player << " " << max << "\n";
delete [] win;
delete [] p;
}
}
it is running properly for the sample input but i am unable to submit it
this code work fine in all custom test case, but not accepting and shown wrong answer, any body helping me out here, whats wrong in it.
#include
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
int maxdiff=0;
int player= 0;
int diff=0;
while(t--)
{
int a,b;
cin>>a>>b;
if (a>b)
{
diff = a-b;
if(diff>maxdiff)
{
maxdiff = diff;
player =1;
}
}
else
{
diff=b-a;
if(diff>maxdiff)
{
maxdiff = diff;
player =2;
}
}
}
cout<<player<<" "<<maxdiff<<endl;
return 0;
}[quote=“jaay, post:167, topic:8657, full:true”]
this code work fine in all custom test case, but not accepting and shown wrong answer, any body helping me out here, whats wrong in it.
#include
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
int maxdiff=0;
int player= 0;
int diff=0;
while(t--)
{
int a,b;
cin>>a>>b;
if (a>b)
{
diff = a-b;
if(diff>maxdiff)
{
maxdiff = diff;
player =1;
}
}
else
{
diff=b-a;
if(diff>maxdiff)
{
maxdiff = diff;
player =2;
}
}
}
cout<<player<<" "<<maxdiff<<endl;
return 0;
}
[/quote]
Please help! I am getting WA but not able to identify corner cases.
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, max = 0;
cin >> t;
int a[t];
for (int i = 0; i < t; ++i) {
int p1, p2;
cin >> p1 >> p2;
a[i] = p1 - p2;
if (abs(a[i]) > abs(max)) {
max = a[i];
}
}
cout << (max < 0 ? "2 " : "1 ") << abs(max);
return 0;
}
For this test-case
5
50 20
10 90
80 20
90 10
50 20
Expected o/p :
1 120
Your o/p:
2 80
Hi! finally solved it. The issue was with the initialization part and here is my new code:
#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, max = 0, a[1] = {0}, b[1] = {0};
cin >> t;
for (int i = 0; i < t; ++i) {
int p1, p2;
cin >> p1 >> p2;
a[i] += p1;
b[i] += p2;
if (abs(a[i]-b[i]) > abs(max)) {
max = a[i]-b[i];
}
}
cout << (max < 0 ? "2 " : "1 ") << abs(max);
return 0;
}
Great
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