Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0849e09

Browse files
recursion
1 parent ee44030 commit 0849e09

19 files changed

+1090
-165
lines changed

‎.classpath‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<classpathentry kind="src" path="src"/>
99
<classpathentry kind="src" path="CSES/Introductory Problems"/>
1010
<classpathentry kind="src" path="heisenburg2.0"/>
11+
<classpathentry kind="src" path="DSAPractice/recursion"/>
1112
<classpathentry kind="output" path="bin"/>
1213
</classpath>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
class Divisible {
5+
static BufferedReader br;
6+
static StringTokenizer st;
7+
8+
static int nextInt() throws IOException {
9+
return Integer.parseInt(next());
10+
}
11+
12+
static String next() throws IOException {
13+
while (st == null || !st.hasMoreTokens()) {
14+
st = new StringTokenizer(br.readLine());
15+
}
16+
return st.nextToken();
17+
}
18+
19+
static long nextLong() throws IOException {
20+
return Long.parseLong(next());
21+
}
22+
23+
public static void main(String args[]) throws IOException {
24+
br = new BufferedReader(new InputStreamReader(System.in));
25+
int t = nextInt();
26+
while (t-- > 0) {
27+
input();
28+
}
29+
br.close();
30+
}
31+
32+
public static void input()throws IOException
33+
{
34+
System.out.println(noOfNumbers(11));
35+
36+
}
37+
38+
static long noOfNumbers(long N) {
39+
// code here
40+
// int c=0,flag=0;
41+
// int a[] = {2,3,5,7};
42+
43+
// for(long i=1;i<=N;i++)
44+
// {
45+
// for(int j=0;j<a.length;j++)
46+
// {
47+
// if(i%a[j]==0)
48+
// {
49+
// flag=1;
50+
// break;
51+
// }
52+
53+
// }
54+
55+
// if(flag==0)
56+
// c++;
57+
// else
58+
// flag=0;
59+
60+
61+
return N-(N/2 + N/5 + N/7 + N/3 -(N/(2*3) + N/(2*5) + N/(2*7) + N/(5*7) + N/(5*3) + N/(7*3)) + N/(2*3*5*7));
62+
63+
}
64+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
class CHEFST {
5+
static BufferedReader br;
6+
static StringTokenizer st;
7+
8+
static int nextInt() throws IOException {
9+
return Integer.parseInt(next());
10+
}
11+
12+
static String next() throws IOException {
13+
while (st == null || !st.hasMoreTokens()) {
14+
st = new StringTokenizer(br.readLine());
15+
}
16+
return st.nextToken();
17+
}
18+
19+
static long nextLong() throws IOException {
20+
return Long.parseLong(next());
21+
}
22+
23+
public static void main(String args[]) throws IOException {
24+
br = new BufferedReader(new InputStreamReader(System.in));
25+
int t = nextInt();
26+
while (t-- > 0) {
27+
input();
28+
}
29+
br.close();
30+
}
31+
32+
public static void input() throws IOException {
33+
long n1 = nextLong();
34+
long n2 = nextLong();
35+
long k = nextLong();
36+
long kx = (k*(k+1))/2;
37+
long min=(long)Math.min(n1,n2);
38+
if (kx<=min)
39+
{
40+
System.out.println(n1 + n2- kx-kx);
41+
}else{
42+
System.out.println(n1 + n2-min-min);
43+
44+
}
45+
46+
47+
}
48+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
class MAXDIFF {
5+
static BufferedReader br;
6+
static StringTokenizer st;
7+
8+
static int nextInt() throws IOException {
9+
return Integer.parseInt(next());
10+
}
11+
12+
static String next() throws IOException {
13+
while (st == null || !st.hasMoreTokens()) {
14+
st = new StringTokenizer(br.readLine());
15+
}
16+
return st.nextToken();
17+
}
18+
19+
static long nextLong() throws IOException {
20+
return Long.parseLong(next());
21+
}
22+
23+
public static void main(String args[]) throws IOException {
24+
br = new BufferedReader(new InputStreamReader(System.in));
25+
int t = nextInt();
26+
while (t-- > 0) {
27+
input();
28+
}
29+
br.close();
30+
}
31+
32+
public static void input()throws IOException
33+
{
34+
int n = nextInt();
35+
int k = nextInt();
36+
37+
int a[]=new int[n];
38+
39+
for(int i =0;i<n;i++)
40+
{
41+
a[i]= nextInt();
42+
}
43+
44+
Arrays.sort(a);
45+
int suml=0;
46+
47+
for(int j =0;j<k;j++)
48+
{
49+
suml+=a[j];
50+
}
51+
int summ=0;
52+
for(int ki = k;ki<n;ki++)
53+
{
54+
summ+=a[ki];
55+
56+
}
57+
int maxdiff=0;
58+
if(k<n-k)
59+
maxdiff = (summ-suml);
60+
else
61+
maxdiff = (suml-summ);
62+
63+
List<Integer> A = new ArrayList<>();
64+
for(int i =0;i<n;i++)
65+
{
66+
A.add(a[i]);
67+
}
68+
69+
Collections.sort(A, Collections.reverseOrder());
70+
71+
int sumlA=0;
72+
73+
for(int j =0;j<k;j++)
74+
{
75+
sumlA+=A.get(j);
76+
}
77+
int summA=0;
78+
for(int ki = k;ki<n;ki++)
79+
{
80+
summA+=A.get(ki);
81+
82+
}
83+
int maxdiffA=0;
84+
if(k<n-k)
85+
maxdiffA = (summA-sumlA);
86+
else
87+
maxdiffA = (sumlA-summA);
88+
89+
90+
91+
if(maxdiff>=maxdiffA)
92+
{ System.out.println(maxdiff);}
93+
else{
94+
System.out.println(maxdiffA);
95+
}
96+
97+
98+
}
99+
}

‎DSAPractice/Greedy Algorithm/Minimum Absolute Difference.java‎

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
class missing_invoices {
5+
static BufferedReader br;
6+
static StringTokenizer st;
7+
8+
static int nextInt() throws IOException {
9+
return Integer.parseInt(next());
10+
}
11+
12+
static String next() throws IOException {
13+
while (st == null || !st.hasMoreTokens()) {
14+
st = new StringTokenizer(br.readLine());
15+
}
16+
return st.nextToken();
17+
}
18+
19+
static long nextLong() throws IOException {
20+
return Long.parseLong(next());
21+
}
22+
23+
public static void main(String args[]) throws IOException {
24+
br = new BufferedReader(new InputStreamReader(System.in));
25+
int t = nextInt();
26+
while (t-- > 0) {
27+
int no_of_companies = nextInt();
28+
29+
company(no_of_companies);
30+
}
31+
br.close();
32+
}
33+
34+
public static void company(int no_of_companies)throws IOException
35+
{
36+
while(no_of_companies-- >0)
37+
{String com = next();
38+
input(com);}
39+
40+
41+
}
42+
public static void input(String com) throws IOException {
43+
int n = nextInt();
44+
45+
int intervals[][] = new int[n][2];
46+
for (int i = 0; i < n; i++) {
47+
48+
intervals[i][0] = nextInt();
49+
intervals[i][1] = nextInt();
50+
}
51+
52+
Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0]));
53+
// System.out.println("/////////////////////");
54+
// for (int[] interval : intervals)
55+
// System.out.println(Arrays.toString(interval));
56+
// System.out.println("////////////////////////");
57+
List<Integer> ans = new ArrayList<>();
58+
List<int[]> l = new ArrayList<>();
59+
for (int[] interval : intervals) {
60+
// for (int[] m : l)
61+
// System.out.println(Arrays.toString(m));
62+
// System.out.println("--------------------------");
63+
64+
if (l.isEmpty()) {
65+
l.add(interval);
66+
} else if (l.get(l.size() - 1)[1] < interval[0] && interval[0]-l.get(l.size() - 1)[1]!=1 ) {
67+
int counter = l.get(l.size() - 1)[1]+1;
68+
while (counter < interval[0]) {
69+
ans.add(counter++);
70+
71+
}
72+
l.add(interval);
73+
} else {
74+
l.add(interval);
75+
continue;
76+
}
77+
}
78+
79+
System.out.println("For "+com+", missing invoices are: "+ans);
80+
}
81+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /