Skip to content

Commit dc65ad5

Browse files
committed
.
1 parent 0293d52 commit dc65ad5

14 files changed

+667
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Dinner by Candlelight","group":"CodeChef - March Lunchtime 2021 Division 2","url":"https://www.codechef.com/LTIME94B/problems/DATE1","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"3\n1 1 1\n1 2 1\n2 2 1\n","output":"1\n2\n2\n","id":1616857661789}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DinnerByCandlelight"}},"batch":{"id":"04ab4a46-b0dd-464b-9bbc-747ad8dbb7b1","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeChef\\March Lunchtime 2021\\Dinner_by_Candlelight.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Gamer","group":"CodeChef - March Lunchtime 2021 Division 2","url":"https://www.codechef.com/LTIME94B/problems/GAMEPROF","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1616856058686,"input":"3 2\n1 3 3\n1 2 5\n4 7 1","output":"4"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Gamer"}},"batch":{"id":"d074a6b4-9ac3-4f59-958d-eaeac326d9c9","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeChef\\March Lunchtime 2021\\Gamer.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Lunchtime","group":"CodeChef - March Lunchtime 2021 Division 2","url":"https://www.codechef.com/LTIME94B/problems/LUNCHTIM","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1616854295965,"input":"1\n5\n1 2 2 3 2","output":"0 1 1 0 0"},{"id":1616854936410,"input":"1\n3\n1 2 1","output":""}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Lunchtime"}},"batch":{"id":"b7cd5b39-7654-498c-9865-220babfad794","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeChef\\March Lunchtime 2021\\Lunchtime.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Racing","group":"CodeChef - March Lunchtime 2021 Division 2","url":"https://www.codechef.com/LTIME94B/problems/RACINGEN","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"2\n60 3 5\n60 3 4\n","output":"YES\nNO\n","id":1616855739122}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Racing"}},"batch":{"id":"b0cafcf3-2a6c-4782-8710-e15a13717435","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeChef\\March Lunchtime 2021\\Racing.cpp"}
44.3 KB
Binary file not shown.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
void solve()
91+
{
92+
93+
int a, y, x;
94+
cin >> a >> y >> x;
95+
int ans = 0;
96+
if (a >= y)
97+
ans = y * x;
98+
else
99+
ans = a * x + 1;
100+
101+
cout << ans << endl;
102+
}
103+
//------------------------------------------------------------------------------
104+
int32_t main()
105+
{
106+
FastIO;
107+
108+
w(T)
109+
solve();
110+
111+
return 0;
112+
}
113+
//------------------------------------------------------------------------------
157 KB
Binary file not shown.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
#include <algorithm>
8+
// #include <unordered_map>
9+
#include <map>
10+
#include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
struct triplet
91+
{
92+
int x, y, v;
93+
};
94+
bool comp(triplet a, triplet b)
95+
{
96+
if (a.x != b.x)
97+
return a.x < b.x;
98+
return a.y < b.y;
99+
}
100+
// returns min index i s.t. A[i] >= x
101+
int bs1(v(triplet) & A, int x)
102+
{
103+
int l = -1;
104+
int r = A.size();
105+
while (r - l > 1)
106+
{
107+
int m = (l + r) >> 1;
108+
if (A[m].x >= x)
109+
r = m;
110+
else
111+
l = m;
112+
}
113+
return r;
114+
}
115+
116+
// returns max index i s.t. A[i] <= x
117+
int bs2(v(triplet) & A, int x)
118+
{
119+
int l = -1;
120+
int r = A.size();
121+
while (r - l > 1)
122+
{
123+
int m = (l + r) >> 1;
124+
if (A[m].x <= x)
125+
l = m;
126+
else
127+
r = m;
128+
}
129+
return l;
130+
}
131+
void solve()
132+
{
133+
int n, k;
134+
cin >> n >> k;
135+
v(triplet) A(n);
136+
for (int i = 0; i < n; i++)
137+
cin >> A[i].x >> A[i].y >> A[i].v;
138+
sort(A.begin(), A.end(), comp);
139+
set<int> st;
140+
for (int i = 0; i < n; i++)
141+
{
142+
st.insert(A[i].x);
143+
st.insert(A[i].y);
144+
}
145+
map<int, int> comp;
146+
int counter = 0;
147+
for (auto &x : st)
148+
{
149+
comp[++counter] = x;
150+
}
151+
int ans = INT64_MIN;
152+
for (int l = 1; l <= counter; l++)
153+
for (int r = l; r <= counter; r++)
154+
{
155+
int p_ans = k * (comp[l] - comp[r]);
156+
int lb = bs1(A, comp[l]);
157+
int ub = bs2(A, comp[r]);
158+
for (int i = lb; i <= ub; i++)
159+
if (A[i].x >= comp[l] and A[i].y <= comp[r])
160+
p_ans += A[i].v;
161+
ans = max(ans, p_ans);
162+
}
163+
cout << ans << endl;
164+
}
165+
//------------------------------------------------------------------------------
166+
int32_t main()
167+
{
168+
FastIO;
169+
170+
// w(T)
171+
solve();
172+
173+
return 0;
174+
}
175+
//------------------------------------------------------------------------------
129 KB
Binary file not shown.

0 commit comments

Comments
 (0)