Dividing Stamps | CodeChef Solution

Hello coders, today we are going to solve Dividing Stamps CodeChef Solution whose Problem Code is DIVIDING.

Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of Stamp Collecting Ð¡ommunity(SCC).

SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC. Mike told them that all stamps of the members could be divided in such a way that i‘th member would get i postage stamps. Now Mike wants to know if he was right. The next SCC meeting is tomorrow. Mike still has no answer.

So, help Mike! There areÂ NÂ members in the SCC,Â i‘th member hasÂ CiÂ stamps in his collection. Your task is to determine if it is possible to redistributeÂ C1Â +Â C2Â + … +Â CnÂ stamps among the members of SCC thus thatÂ i‘th member would getÂ iÂ stamps.

Input Format

The first line contains one integer N, denoting the number of members of SCC.

The second line containsÂ NÂ integersÂ Ci, denoting the numbers of the stamps in the collection ofÂ i‘th member.

Output Format

The first line should containÂ YES, if we can obtain the required division, otherwiseÂ NO.

Constraints

• 1 â‰¤Â NÂ â‰¤ 100 000;
• 1 â‰¤Â CiÂ â‰¤ 109.

Examples

Sample Input 0

``````5
7 4 1 1 2``````

Sample Output 0

``YES``

Sample Input 1

``````5
1 1 1 1 1
``````

Sample Output 1

``NO``

Solution – Dividing Stamps

C++

```#include<bits/stdc++.h>
using namespace std;
typedef vector<long long int> vi;
typedef long long ll;

int main(){
ll n;cin>>n;
ll sum = 0;
for(ll i =0;i<n;i++){
ll num ;cin>>num;
sum+=num;
}
if(sum == (n*(n+1))/2)cout<<"YES\n";
else cout<<"NO\n";
}
```

Python

```N=int(input())
c=[int(x) for x in input().split()]
if N*(N+1)/2 == sum(c):
print('YES')
else:
print('NO')```

Java

```/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int nSum = 0;
for(int i=n ; i>0 ; i--){
nSum+=i;
}
int[] arr = new int[n];
int arrSum = 0;
for(int j=0 ; j<n ; j++){
arr[j] = sc.nextInt();
arrSum+=arr[j];
}
if(arrSum==nSum){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
```

Disclaimer: The above Problem (Dividing Stamps) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.