oops what the hell i did
Not much. Just tried it for 2 hours XD
it should be 7 mine is correct
I didn’t understand. Can you show for some n as a example
hii bro why do sort in this questions. and what is the need for this
all players play optimally. so 1st turn chose max,2nd turn chose 2nd max …
Anyone please tell me why most of the people do sort and reverse in first question??
Yeah, you got right bro… @admin please look into this matter…
and I don’t this should be rated contest anymore…
yes mine is coming 7
1 2 3 4 5 6 7
LCM(4,5)=20;
LCM(6,7)=42;
1 2 3 20 20 42 4 2
LCM(20,42);
LCM(20,42)=420;
1 2 3 420 420 420 420
4 + 3 = 7 operations.
bhaii isme galti kya hai batade ,aise bhi toh kr skte hain
please can you eleborate this
it should be unrated
Can anyone explain what is meant by Highest power of all primes?
hey consider exp : n=11 , 5,7,8,9,11 – give the same lcm for 1…11(LCM :27,720). so how to find the number of (L) as in i know that --> 5,7,8,9,11 (LCM :27,720), --> so for a particular n --> how to find
number of (L) since (8,9 are not prime) i got confused
What is wrong in this code?? Please anyone tell me
`
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e9 + 7
void solve()
{
ll n;
cin >> n;
ll arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
ll p1 = 0;
ll p2 = 0;
p1 += arr[0];
p2 += arr[1];
for (int i = 2; i < n; i++)
{
if (i % 2 == 0)
{
p2 += arr[i];
}
else
{
p1 += arr[i];
}
}
if (p2 > p1)
{
cout << "second" << endl;
}
else if (p1 == p2)
{
cout << "draw" << endl;
}
else
{
cout << "first" << endl;
}
}
int main()
{
int tt;
cin >> tt;
while (tt-- > 0)
{
solve();
}
return 0;
}
`
thing is each round a player always picks the highest number because he plays optimally and your goal to maximize your sum. So sorting will make your job easier. But there is one more constraint that is, second player could pick either one or twice at the first round. If he playing optimally he will always pick the 2nd and 3rd largest element as the first element will be picked by player 1.From this point players pick alternatively. Whoever have there sum as the highest value wins else it is a draw. Also be aware of the edge case
1(always player 1 wins),
n=2(if any one of the value larger player 1 wins else it is draw)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e9 + 7
void solve()
{
ll n;
cin >> n;
ll arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
ll p1 = 0;
ll p2 = 0;
sort(arr, arr+n);
p1 += arr[0];
p2 += arr[1];
for (int i = 2; i < n; i++)
{
if (i % 2 == 0)
{
p2 += arr[i];
}
else
{
p1 += arr[i];
}
}
if (p2 > p1)
{
cout << "second" << endl;
}
else if (p1 == p2)
{
cout << "draw" << endl;
}
else
{
cout << "first" << endl;
}
}
int main()
{
int tt;
cin >> tt;
while (tt-- > 0)
{
solve();
}
return 0;
}
Sir what is wrong in this code??