Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the November Challenge Files #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions NOV20B/ADADISH.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Link to the problem:
https://www.codechef.com/NOV20B/problems/ADADISH
Link to my profile:
https://www.codechef.com/users/oj_17
*/


#include <iostream>
#include<algorithm>
using namespace std;

int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int x=0,y=0;
sort(arr,arr+n,greater<int>());
x=arr[0];
for(int i=1;i<n;i++)
{
if(y<=x)
y+=arr[i];
else
x+=arr[i];
}
if(x==y)
cout<<x<<"\n";
else if(x>y)
cout <<x<<"\n";
else if(y>x)
cout<<y<<"\n";

}
return 0;
}
65 changes: 65 additions & 0 deletions NOV20B/Restore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

/*
Link to the problem:
https://www.codechef.com/NOV20B/problems/RESTORE
Link to my profile:
https://www.codechef.com/users/oj_17
*/
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
static int max=4000000;
static ArrayList<Integer>v=new ArrayList<>();
static boolean primes[]=new boolean[max+1];
public static void generatePrimes()
{

for(int i=0;i<=max;i++)
primes[i]=true;
for(int p=2;p*p<=max;p++)
{
if(primes[p]==true)
{
for(int i=p*p;i<=max;i+=p)
primes[i]=false;
}
}
for(int i=2;i<=max;i++)
{
if(primes[i]==true)
v.add(i);
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
generatePrimes();
while (t-- >0)
{
int n=sc.nextInt();
int b[]=new int[n];
ArrayList<Integer> a=new ArrayList<>();
HashMap<Integer,Integer>m=new HashMap<>();
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
m.put(b[i],m.getOrDefault(b[i],0)+1);
}
for(int i=0;i<n;i++)
{
a.add(v.get(b[i]));
m.put(b[i],m.get(b[i])-1);
}
for(int i:a)
System.out.print(i+" ");
System.out.println();
}
}
}