Showing posts with label Codeforces. Show all posts
Showing posts with label Codeforces. Show all posts

10 March 2018

Codeforces 946 A Partition

Explanation

category : Easy

You just need to sum up all numbers. If you find any negative number just make it positive.

Source code link

09 March 2018

Codeforces 950 A Left-handers, Right-handers and Ambidexters

Problem Explanation

Category: Easy

One have to find out maximum number of player which is even. Check the amount of left hand player  right hand player. If the amount is not same then take a amount of player from ambidexters, which can make equal number for both left hand and right hand. after taking some player from ambidexters , if still there are some player remains in ambidexters then divide the player among left hand and right hand players. 
If the amount of ambidexters player is zero the just squre the value which is minimum of left hand and right hand players. 

Some test case
10 12 10
28
1 0 1
2
2 4 0
4
3 6 9
18
5 5 5
14

Source code link Click here

01 March 2018

Codeforces 939 A Love Triangle

/***
Md. Nazmul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include <iomanip>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size)  for(int i=0 ; i<size ; i++) cin>>array[i]  ;
#define new_line  pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
#define lowest_int -2147483647

int main()
{
    int n;
    int data[5010];
    sc("%d",&n);
    for(int i=0 ; i<n ; i++)
        sc("%d",&data[i+1]);
    bool notGet = false ;
    for(int i=1 ; i<n+1 ; i++)
    {
        if( i == data[data[data[i]]])
        {
            pf("YES");
            notGet = true;
            break;
        }
    }
    if(notGet == false)
        pf("NO");

    return 0;
}



Codeforces 940 A Points on the line

/***
Md. Nazmul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include <iomanip>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size)  for(int i=0 ; i<size ; i++) cin>>array[i]  ;
#define new_line  pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
#define lowest_int -2147483647

int main()
{
    int n,d,p;
    vector<int>data;
    int ans=-1;

    sc("%d %d",&n,&d);
    for(int i=1 ; i<=n ; i++)
    {
        sc("%d",&p);
        data.pb(p);
    }
    sort(data.begin(),data.end());

    for(int i=0;i<n;i++)for(int j=i;data[j]-data[i]<=d&&j<n;j++)
if(j-i+1>ans)ans=j-i+1;
    pf("%d",n-ans);
    return 0;
}


UVA 10679 - I Love Strings!!