C #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll solve(ll l, ll r,ll k){
ll len = (r-l+1);
if(len<k)
return 0;
if(l==r)
return 0;
ll x=0,y=0;
ll mid = (l+r)/2;
if(len%2==0){
y = solve(l,mid,k) + solve(mid+1,r,k);
}else{
x = mid + solve(l,mid-1,k) + solve(mid+1,r,k);
}
return x+y;
}
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
ll l=1,r=n;
cout<< solve(l,r,k)<<'\n';
}
return 0;
}
CF 🔥‼️
B DONE ✅✅ only 21 rs
C. DONE ✅✅
C. DONE ✅✅
C DONE ✅ ✅ only 29 rs
Dmm @codercpp001
PAYPAL ACCEPTED ‼️
BINANCE ACCEPTED ‼️
anyone willing to buy codechef 4 star dm me please bhai faltu mein message matt karna
Читать полностью…I don't understand why u guys sell or buy IDs like does it make ur CV strong or just to flex ???
Читать полностью…connecting wells done ✅✅
connecting wells done ✅✅
Constuct permutation done ✅
Constuct permutation done ✅
DMM FAST @codercpp001
E:
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
string a, b, c;
cin >> a >> b >> c;
int n = a.size();
int m = b.size();
// Initialize DP table with (n+1) x (m+1) dimensions
// Using a vector of vectors for flexibility
// Initialize all values to a large number
const int INF = 1e9;
vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF));
// Base case: both a and b are empty
dp[0][0] = 0;
// Fill the DP table
for(int i = 0; i <= n; ++i){
for(int j = 0; j <= m; ++j){
if(i == 0 && j == 0) continue;
// Current position in c is (i + j -1)
int pos = i + j -1;
if(pos >= c.size()){
// This should not happen as |c| = |a| + |b|
continue;
}
// If we take a character from a
if(i > 0){
int cost = dp[i-1][j];
if(a[i-1] != c[pos]){
cost +=1;
}
dp[i][j] = min(dp[i][j], cost);
}
// If we take a character from b
if(j > 0){
int cost = dp[i][j-1];
if(b[j-1] != c[pos]){
cost +=1;
}
dp[i][j] = min(dp[i][j], cost);
}
}
}
// The answer is dp[n][m]
cout << dp[n][m] << "\n";
}
}
CF E SOLUTION
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<ll> a(n);
ll even = 0, odd = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
if(i % 2) odd += a[i];
else even += a[i];
}
ll target = (even + odd) / n;
if((even + odd) % n != 0) {
cout << "NO\n";
return;
}
ll req_even = target * ((n + 1) / 2);
ll req_odd = target * (n / 2);
if(even == req_even && odd == req_odd) cout << "YES\n";
else cout << "NO\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--) solve();
return 0;
}
B sol