Skip to content

Commit 2e14279

Browse files
committed
leetcode biweekly 100
1 parent bb35f4f commit 2e14279

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
long long a,b,c,d;
12+
cin>>a>>b>>c>>d;
13+
if(d<b){
14+
cout<<-1<<endl;
15+
return 0;
16+
}
17+
long long step = d-b;
18+
a+=step;
19+
if(a<c){
20+
cout<<-1<<endl;
21+
}
22+
else{
23+
step+=(a-c);
24+
cout<<step<<endl;
25+
}
26+
return 0;
27+
}
28+
int main()
29+
{
30+
int testCase=1;
31+
cin>>testCase;
32+
while(testCase--){
33+
solve();
34+
}
35+
return 0;
36+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int distMoney(int money, int children)
15+
{
16+
int child=0;
17+
bool flag=0;
18+
if(money<children){
19+
return -1;
20+
}
21+
money-=children;
22+
for(int i=1;i<children;i++){
23+
if(money>=7){
24+
child++;
25+
money-=7;
26+
}
27+
else{
28+
return child;
29+
}
30+
}
31+
if(money==3){
32+
if(child>0){
33+
child--;
34+
}
35+
else{
36+
return -1;
37+
}
38+
}
39+
else if(money==7){
40+
child++;
41+
}
42+
43+
return child;
44+
}
45+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int maximizeGreatness(vector<int> &nums)
15+
{
16+
int n=nums.size();
17+
vector<pair<int,int>> v1(n);
18+
vector<int> v2(n);
19+
int count=0;
20+
for(int i=0;i<n;i++){
21+
v1[i]={nums[i],i};
22+
v2[i]=nums[i];
23+
}
24+
sort(v2.begin(),v2.end());
25+
sort(v1.begin(),v1.end());
26+
int pos=0;
27+
28+
for(int i=0;i<n;i++){
29+
while(pos<n && v1[i].>=firstv2[pos]){
30+
pos++;
31+
}
32+
if(pos<n){
33+
count++;
34+
pos++;
35+
}
36+
else{
37+
break;
38+
}
39+
}
40+
return count;
41+
42+
}
43+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
typedef pair<long long, long long> pi;
12+
13+
class Solution
14+
{
15+
public:
16+
long long findScore(vector<int> &nums)
17+
{
18+
long long ans=0;
19+
int n=nums.size();
20+
21+
// min heap
22+
priority_queue<pi, vector<pi>, greater<pi>> pq;
23+
vector<bool> check(nums.size(), false);
24+
25+
for(int i=0;i<n;i++){
26+
pq.push({nums[i],i});
27+
}
28+
while(pq.size()){
29+
long long mini=pq.top().first;
30+
long long pos=pq.top().second;
31+
if(check[pos]==false){
32+
ans+=mini;
33+
if(pos+1<n){
34+
check[pos+1]=true;
35+
}
36+
if(pos>=1){
37+
check[pos-1]=true;
38+
}
39+
}
40+
pq.pop();
41+
}
42+
return ans;
43+
}
44+
};

0 commit comments

Comments
 (0)