HLPSAM-Editorial

PROBLEM LINK:

Contest: Hey Newbees, Here is Some Honey(Round 2)
Contest Link: Contest Page | CodeChef
Author: aimon_123
Tester: arghya_n
Editorialist: aimon_123

DIFFICULTY:
SIMPLE.

PREREQUISITES:
Greedy,Math.

Tutorial:

In the problem , At first, you have to find how much odd number and how much even number in there from 1 to n .
Then you have to find the number of operation performed by even number denoted e in code and the number of operation performed by odd number denoted o in the code .We can prove that , total operation = number of operation using even number+number of operation using odd number =(e*(e-1))/2 + (o*(o-1))/2
Total earning of Sam is = total operation * 2 = (e*(e-1)) + (o*(o-1))
Profit / loss (denoted m in the code) = x - Total earning of Sam
If(m > 0) Print m and profit,if(m < 0) print -m and loss,if(m=0) print 0 and null.

Source code :

CPP

//Code by ASIM FOIZE AIMON
//CSE’19;CUET
//avoid copy paste//Hit the friend button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl “\n”
#define int int64_t
#define ll long long
#define yes printf(“YES\n”)
#define no printf(“NO\n”)

int32_t main()
{

ll t;
cin>>t;
while(t--)
{
        ll a[100001],b[100001],c=0,d=0,e,f,m,n,p,x,y,z,i,j,k;
        string s;
        cin>>n>>x;
        if(n%2==0)
        {
        c=n/2;
        d=n/2;
        }
       else
       {
        c=n/2;
        d=n/2+1;
       }
       y=(c*(c-1))/2+(d*(d-1))/2;
      m=x-(y*2);
      if(m<0)
      cout<< -m << " " <<  "Profit" << endl;
      else if(m>0)
      cout<< m << " " << "Loss" << endl;
       else
       cout<< 0 << " " << " Null "  << endl;
}

}

1 Like