Skip to content

Commit 7b06344

Browse files
committed
leetcode and hackerearth contest
1 parent 5c6d635 commit 7b06344

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3528
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
#include <ext/pb_ds/assoc_container.hpp>
7+
#include <ext/pb_ds/tree_policy.hpp>
8+
using namespace std;
9+
using namespace __gnu_pbds;
10+
typedef long long ll ;
11+
typedef vector<ll> vl;
12+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
13+
// define values.
14+
// #define mod 1000000007
15+
#define phi 1.618
16+
/* Abbrevations */
17+
#define ff first
18+
#define ss second
19+
#define mp make_pair
20+
#define line cout<<endl;
21+
#define pb push_back
22+
#define Endl "\n"
23+
// loops
24+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
25+
// Some print
26+
#define no cout<<"No"<<endl;
27+
#define yes cout<<"Yes"<<endl;
28+
// sort
29+
#define all(V) (V).begin(),(V).end()
30+
#define srt(V) sort(all(V))
31+
#define srtGreat(V) sort(all(V),greater<ll>())
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
// some extra
34+
#define sz(V) ll(V.size())
35+
/* ONLINE JUDGE */
36+
// #ifdef ONLINE_JUDGE
37+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
38+
// #endif
39+
// template
40+
template <typename T>
41+
T mymax(T x,T y)
42+
{
43+
return (x>y)?x:y;
44+
}
45+
// function
46+
47+
ll power(ll x,ll y,ll mod)
48+
{
49+
ll res=1;
50+
// x=x%mod;
51+
while(y>0)
52+
{
53+
if(y%2==1)
54+
{
55+
res*=x;
56+
// res=res%mod;
57+
}
58+
y/=2; x*=x; // x=x%mod;
59+
}
60+
return res;
61+
}
62+
ll str_to_num(string s)
63+
{
64+
return stoi(s);
65+
}
66+
67+
string num_to_str(ll num)
68+
{
69+
return to_string(num);
70+
}
71+
// datatype definination
72+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
73+
74+
/* ascii value
75+
A=65,Z=90,a=97,z=122
76+
*/
77+
/* -----------------------------------------------------------------------------------*/
78+
79+
80+
ll solve()
81+
{
82+
ll n,m,k;
83+
cin>>n>>m>>k;
84+
ll diff=m;
85+
for(ll i=0;i<=max(n,m);i++)
86+
{
87+
if(diff<0)
88+
{
89+
no
90+
return 0;
91+
}
92+
ll ans=(n*i);
93+
ans=k-ans;
94+
if(diff==0)
95+
{
96+
if(ans==0)
97+
{
98+
yes
99+
}
100+
else
101+
{
102+
no
103+
}
104+
return 0;
105+
}
106+
if(ans>=0&&ans%diff==0&&ans/diff<=n)
107+
{
108+
yes
109+
return 0;
110+
}
111+
if(ans<0)
112+
{
113+
no
114+
return 0;
115+
}
116+
diff-=2;
117+
}
118+
no
119+
return 0;
120+
}
121+
122+
int main()
123+
{
124+
speed;
125+
// freopen("input.txt","r",stdin);
126+
// freopen("output.txt","w",stdout);
127+
ll TestCase=1;
128+
cin>>TestCase;
129+
while(TestCase--)
130+
{
131+
solve();
132+
}
133+
}
134+
135+
/* stuff you should look before submission
136+
* int overflow
137+
* special test case (n=0||n=1||n=2)
138+
* don't get stuck on one approach if you get wrong answer
139+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
#include <ext/pb_ds/assoc_container.hpp>
7+
#include <ext/pb_ds/tree_policy.hpp>
8+
using namespace std;
9+
using namespace __gnu_pbds;
10+
typedef long long ll ;
11+
typedef vector<ll> vl;
12+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
13+
// define values.
14+
// #define mod 1000000007
15+
#define phi 1.618
16+
/* Abbrevations */
17+
#define ff first
18+
#define ss second
19+
#define mp make_pair
20+
#define line cout<<endl;
21+
#define pb push_back
22+
#define Endl "\n"
23+
// loops
24+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
25+
// Some print
26+
#define no cout<<"NO"<<endl;
27+
#define yes cout<<"YES"<<endl;
28+
// sort
29+
#define all(V) (V).begin(),(V).end()
30+
#define srt(V) sort(all(V))
31+
#define srtGreat(V) sort(all(V),greater<ll>())
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
// some extra
34+
#define sz(V) ll(V.size())
35+
/* ONLINE JUDGE */
36+
// #ifdef ONLINE_JUDGE
37+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
38+
// #endif
39+
// template
40+
template <typename T>
41+
T mymax(T x,T y)
42+
{
43+
return (x>y)?x:y;
44+
}
45+
// function
46+
47+
ll power(ll x,ll y,ll mod)
48+
{
49+
ll res=1;
50+
// x=x%mod;
51+
while(y>0)
52+
{
53+
if(y%2==1)
54+
{
55+
res*=x;
56+
// res=res%mod;
57+
}
58+
y/=2; x*=x; // x=x%mod;
59+
}
60+
return res;
61+
}
62+
ll str_to_num(string s)
63+
{
64+
return stoi(s);
65+
}
66+
67+
string num_to_str(ll num)
68+
{
69+
return to_string(num);
70+
}
71+
// datatype definination
72+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
73+
74+
/* ascii value
75+
A=65,Z=90,a=97,z=122
76+
*/
77+
/* -----------------------------------------------------------------------------------*/
78+
79+
80+
ll solve()
81+
{
82+
ll n;
83+
cin>>n;
84+
ll maxo=0;
85+
ll time=0,order=0;
86+
vector<pair<pair<ll,ll>,ll>> v;
87+
while(n--)
88+
{
89+
ll l,r,x;
90+
cin>>l>>r>>x;
91+
v.push_back({{r,l},x});
92+
}
93+
srt(v);
94+
for(auto x:v)
95+
{
96+
order+=x.ss;
97+
time=x.ff.ff;
98+
ll ans=ceil(double(double(order)/double(time)));
99+
maxo=max(maxo,ans);
100+
}
101+
cout<<maxo<<endl;
102+
return 0;
103+
}
104+
105+
int main()
106+
{
107+
speed;
108+
// freopen("input.txt","r",stdin);
109+
// freopen("output.txt","w",stdout);
110+
ll TestCase=1;
111+
cin>>TestCase;
112+
while(TestCase--)
113+
{
114+
solve();
115+
}
116+
}
117+
118+
/* stuff you should look before submission
119+
* int overflow
120+
* special test case (n=0||n=1||n=2)
121+
* don't get stuck on one approach if you get wrong answer
122+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
#include <ext/pb_ds/assoc_container.hpp>
7+
#include <ext/pb_ds/tree_policy.hpp>
8+
using namespace std;
9+
using namespace __gnu_pbds;
10+
typedef long long ll ;
11+
typedef vector<ll> vl;
12+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
13+
// define values.
14+
// #define mod 1000000007
15+
#define phi 1.618
16+
/* Abbrevations */
17+
#define ff first
18+
#define ss second
19+
#define mp make_pair
20+
#define line cout<<endl;
21+
#define pb push_back
22+
#define Endl "\n"
23+
// loops
24+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
25+
// Some print
26+
#define no cout<<"NO"<<endl;
27+
#define yes cout<<"YES"<<endl;
28+
// sort
29+
#define all(V) (V).begin(),(V).end()
30+
#define srt(V) sort(all(V))
31+
#define srtGreat(V) sort(all(V),greater<ll>())
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
// some extra
34+
#define sz(V) ll(V.size())
35+
/* ONLINE JUDGE */
36+
// #ifdef ONLINE_JUDGE
37+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
38+
// #endif
39+
// template
40+
template <typename T>
41+
T mymax(T x,T y)
42+
{
43+
return (x>y)?x:y;
44+
}
45+
// function
46+
47+
ll power(ll x,ll y,ll mod)
48+
{
49+
ll res=1;
50+
// x=x%mod;
51+
while(y>0)
52+
{
53+
if(y%2==1)
54+
{
55+
res*=x;
56+
// res=res%mod;
57+
}
58+
y/=2; x*=x; // x=x%mod;
59+
}
60+
return res;
61+
}
62+
ll str_to_num(string s)
63+
{
64+
return stoi(s);
65+
}
66+
67+
string num_to_str(ll num)
68+
{
69+
return to_string(num);
70+
}
71+
// datatype definination
72+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
73+
74+
/* ascii value
75+
A=65,Z=90,a=97,z=122
76+
*/
77+
/* -----------------------------------------------------------------------------------*/
78+
79+
ll solve()
80+
{
81+
ll n;
82+
cin>>n;
83+
map<ll,ll> mini;
84+
map<ll,ll> maxo;
85+
map<ll,bool> check;
86+
for(ll i=0;i<n;i++)
87+
{
88+
ll temp;
89+
cin>>temp;
90+
if(check[temp]==false)
91+
{
92+
check[temp]=true;
93+
mini[temp]=i;
94+
}
95+
maxo[temp]=i;
96+
}
97+
ll sum=0;
98+
for(auto x:mini)
99+
{
100+
sum+=abs(maxo[x.ff]-mini[x.ff]);
101+
}
102+
cout<<sum<<endl;
103+
return 0;
104+
}
105+
106+
int main()
107+
{
108+
speed;
109+
// freopen("input.txt","r",stdin);
110+
// freopen("output.txt","w",stdout);
111+
ll TestCase=1;
112+
cin>>TestCase;
113+
while(TestCase--)
114+
{
115+
solve();
116+
}
117+
}
118+
119+
/* stuff you should look before submission
120+
* int overflow
121+
* special test case (n=0||n=1||n=2)
122+
* don't get stuck on one approach if you get wrong answer
123+
*/

0 commit comments

Comments
 (0)