Skip to content

Commit e6dea02

Browse files
committed
biweekly 105
1 parent d53fe2d commit e6dea02

File tree

6 files changed

+212
-0
lines changed

6 files changed

+212
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
int n;
12+
cin>>n;
13+
vector<int> v(n);
14+
for(auto &x1:v){
15+
cin>>x1;
16+
}
17+
int minOdd=INT_MAX;
18+
for(auto x1:v){
19+
if(x1&1){
20+
minOdd=min(minOdd,x1);
21+
}
22+
}
23+
bool makeEven=true,makeOdd=true;
24+
// for odd
25+
for(auto x:v){
26+
if(!(x&1) && x<=minOdd){
27+
makeOdd=false;
28+
}
29+
}
30+
// make even
31+
for(auto x:v){
32+
if((x&1) && x<=minOdd){
33+
makeEven=false;
34+
}
35+
}
36+
if(makeOdd || makeEven){
37+
cout<<"YES"<<endl;
38+
}
39+
else{
40+
cout<<"NO"<<endl;
41+
}
42+
return 0;
43+
}
44+
int main()
45+
{
46+
int testCase=1;
47+
cin>>testCase;
48+
while(testCase--){
49+
solve();
50+
}
51+
return 0;
52+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
int x,k;
12+
cin>>x>>k;
13+
if(x%k){
14+
cout<<1<<endl<<x<<endl;
15+
}
16+
else{
17+
cout<<2<<endl<<1<<" "<<x-1<<endl;
18+
}
19+
return 0;
20+
}
21+
int main()
22+
{
23+
int testCase=1;
24+
cin>>testCase;
25+
while(testCase--){
26+
solve();
27+
}
28+
return 0;
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
int n;
12+
string s;
13+
cin>>n>>s;
14+
int count=0,maxo=0;
15+
for(int i=0;i<n;i++){
16+
if(i==0){
17+
count=1;
18+
}
19+
else{
20+
if(s[i]==s[i-1]){
21+
count++;
22+
}
23+
else{
24+
count=1;
25+
}
26+
}
27+
maxo=max(maxo,count);
28+
}
29+
cout<<maxo+1<<endl;
30+
return 0;
31+
}
32+
int main()
33+
{
34+
int testCase=1;
35+
cin>>testCase;
36+
while(testCase--){
37+
solve();
38+
}
39+
return 0;
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
bool check(int i){
15+
string s=to_string(i*i);
16+
17+
}
18+
int punishmentNumber(int n)
19+
{
20+
int sum=0;
21+
for(int i=1;i<=n;i++){
22+
if(check(i)){
23+
sum+=(i*i);
24+
}
25+
}
26+
return sum;
27+
}
28+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 minExtraChar(string s, vector<string> &dictionary)
15+
{
16+
int n = s.size();
17+
vector<int> dp(n + 1, n);
18+
dp[0] = 0;
19+
for (int i = 0; i < n; i += 1)
20+
{
21+
for (auto t : dictionary)
22+
{
23+
if (s.substr(i, t.size()) == t)
24+
{
25+
dp[i + t.size()] = min(dp[i + t.size()], dp[i]);
26+
}
27+
}
28+
dp[i + 1] = min(dp[i + 1], dp[i] + 1);
29+
}
30+
return dp.back();
31+
}
32+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
long long maxStrength(vector<int> &nums)
15+
{
16+
long long ans = nums[0];
17+
for (int i = 1; i < (1 << nums.size()); i += 1)
18+
{
19+
long long pans = 1;
20+
for (int j = 0; j < nums.size(); j += 1)
21+
{
22+
if ((i >> j) & 1)
23+
{
24+
pans = pans * nums[j];
25+
}
26+
}
27+
ans = max(ans, pans);
28+
}
29+
return ans;
30+
}
31+
};

0 commit comments

Comments
 (0)