-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Sushank34/master
Added my LTIME95B answers in Codechef
- Loading branch information
Showing
3 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import java.util.*; | ||
import java.lang.*; | ||
import java.io.*; | ||
|
||
class Codechef | ||
{ | ||
static class FastReader | ||
{ | ||
BufferedReader br; | ||
StringTokenizer st; | ||
|
||
public FastReader() | ||
{ | ||
br = new BufferedReader(new | ||
InputStreamReader(System.in)); | ||
} | ||
|
||
String next() | ||
{ | ||
while (st == null || !st.hasMoreElements()) | ||
{ | ||
try | ||
{ | ||
st = new StringTokenizer(br.readLine()); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
return st.nextToken(); | ||
} | ||
|
||
int nextInt() | ||
{ | ||
return Integer.parseInt(next()); | ||
} | ||
|
||
|
||
long nextLong() | ||
{ | ||
return Long.parseLong(next()); | ||
} | ||
|
||
double nextDouble() | ||
{ | ||
return Double.parseDouble(next()); | ||
} | ||
|
||
String nextLine() | ||
{ | ||
String str = ""; | ||
try | ||
{ | ||
str = br.readLine(); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
return str; | ||
} | ||
} | ||
public static void main(String[] args) throws java.lang.Exception{ | ||
FastReader sc=new FastReader(); | ||
int n=sc.nextInt(); | ||
long[] arr=new long[n]; | ||
long sum=0; | ||
for(int i=0;i<n;i++) { | ||
arr[i]=sc.nextLong(); | ||
sum=(sum+arr[i])%1000000007; | ||
} | ||
|
||
int q=sc.nextInt(),x; | ||
for(int i=0;i<q;i++) { | ||
x=sc.nextInt(); | ||
if(sum<0) { | ||
sum=(((sum*2)%1000000007)+1000000007)%1000000007; | ||
} | ||
else { | ||
sum=(sum*2)%1000000007; | ||
} | ||
System.out.print(sum+"\n"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import java.util.*; | ||
import java.lang.*; | ||
import java.io.*; | ||
|
||
class Codechef | ||
{ | ||
static class FastReader | ||
{ | ||
BufferedReader br; | ||
StringTokenizer st; | ||
|
||
public FastReader() | ||
{ | ||
br = new BufferedReader(new | ||
InputStreamReader(System.in)); | ||
} | ||
|
||
String next() | ||
{ | ||
while (st == null || !st.hasMoreElements()) | ||
{ | ||
try | ||
{ | ||
st = new StringTokenizer(br.readLine()); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
return st.nextToken(); | ||
} | ||
|
||
int nextInt() | ||
{ | ||
return Integer.parseInt(next()); | ||
} | ||
|
||
|
||
long nextLong() | ||
{ | ||
return Long.parseLong(next()); | ||
} | ||
|
||
double nextDouble() | ||
{ | ||
return Double.parseDouble(next()); | ||
} | ||
|
||
String nextLine() | ||
{ | ||
String str = ""; | ||
try | ||
{ | ||
str = br.readLine(); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
return str; | ||
} | ||
} | ||
public static void main(String[] args) throws java.lang.Exception{ | ||
FastReader sc=new FastReader(); | ||
int t=sc.nextInt(); | ||
while(t-->0) { | ||
int n=sc.nextInt(); | ||
long w=sc.nextLong(); | ||
long wr=sc.nextLong(); | ||
long[] wt=new long[n]; | ||
Hashtable<Long,Long> d= new Hashtable<>(); | ||
long temp; | ||
for(int i=0;i<n;i++) { | ||
wt[i]=sc.nextLong(); | ||
if(d.get(wt[i])==null) { | ||
d.put(wt[i],(long) 1); | ||
} | ||
else { | ||
temp=(long) d.get(wt[i]); | ||
d.put(wt[i],temp+1); | ||
} | ||
} | ||
long temp2,resw=0; | ||
for (Enumeration k=d.keys(),ele=d.elements();k.hasMoreElements();) | ||
{ | ||
temp=(long) k.nextElement(); | ||
temp2=(long) ele.nextElement(); | ||
if(temp2>=2) { | ||
if(temp2%2==0) { | ||
resw=resw+temp*temp2; | ||
} | ||
else { | ||
resw=resw+temp*(temp2-1); | ||
} | ||
} | ||
} | ||
if(resw+wr>=w) { | ||
System.out.print("YES\n"); | ||
} | ||
else { | ||
System.out.print("NO\n"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import java.util.*; | ||
import java.lang.*; | ||
import java.io.*; | ||
|
||
class Codechef | ||
{ | ||
static class FastReader | ||
{ | ||
BufferedReader br; | ||
StringTokenizer st; | ||
|
||
public FastReader() | ||
{ | ||
br = new BufferedReader(new | ||
InputStreamReader(System.in)); | ||
} | ||
|
||
String next() | ||
{ | ||
while (st == null || !st.hasMoreElements()) | ||
{ | ||
try | ||
{ | ||
st = new StringTokenizer(br.readLine()); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
return st.nextToken(); | ||
} | ||
|
||
int nextInt() | ||
{ | ||
return Integer.parseInt(next()); | ||
} | ||
|
||
|
||
long nextLong() | ||
{ | ||
return Long.parseLong(next()); | ||
} | ||
|
||
double nextDouble() | ||
{ | ||
return Double.parseDouble(next()); | ||
} | ||
|
||
String nextLine() | ||
{ | ||
String str = ""; | ||
try | ||
{ | ||
str = br.readLine(); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
return str; | ||
} | ||
} | ||
public static void main(String[] args) throws java.lang.Exception{ | ||
FastReader sc=new FastReader(); | ||
int t=sc.nextInt(); | ||
while(t-->0) { | ||
int l=sc.nextInt(); | ||
String s=sc.next(); | ||
int ones=0,zero=0; | ||
int flag=0; | ||
for(int i=0;i<l;i++) { | ||
if(s.charAt(i)=='1') { | ||
ones++; | ||
} | ||
if(s.charAt(i)=='0') { | ||
zero++; | ||
} | ||
if(ones>=zero) { | ||
flag=1; | ||
break; | ||
} | ||
} | ||
if(flag==1) { | ||
System.out.print("YES\n"); | ||
} | ||
else { | ||
System.out.print("NO\n"); | ||
} | ||
} | ||
} | ||
} |