Codeforces|Leetcode|Codechef free solutions
Kanalga Telegram’da o‘tish
Free codeforces, Codechef, Leetcode solutions are available 😍😍😍😍😍😍 Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. 🥳🥳🥳🤩🤩🤩 Dm @Cpsoln if you want help in coding round.
Ko'proq ko'rsatish4 317
Obunachilar
Ma'lumot yo'q24 soatlar
-137 kunlar
-5230 kunlar
Postlar arxiv
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
// my function
void mrinfamous()
{
ll n,m;cin>>n>>m;
ll a[n];
rep(i,n)cin>>a[i];
ll b[m];
rep(i,m)cin>>b[i];
sort(a,a+n);sort(b,b+m);
ll pa[n];
ll pb[m];
rep(i,n){
if(i==0)pa[i]=a[i];
else pa[i]=a[i]+pa[i-1];
}
rep(i,m){
if(i==0)pb[i]=b[i];
else pb[i]=pb[i-1]+b[i];
}
ll sa[n];
ll sb[m];
for(ll i=n-1;i>=0;i--)
{
if(i==n-1)sa[i]=a[i];
else sa[i]=sa[i+1]+a[i];
}
for(ll i=m-1;i>=0;i--)
{
if(i==m-1)sb[i]=b[i];
else sb[i]=sb[i+1]+b[i];
}
ll ans=-1;
for(ll i=0;i<=n;i++){
ll npa=i;
ll nna=n-i;
ll npb=n-i;
ll nnb=i;
ll sum;
if(i==0){
sum=sb[m-npb]-pa[n-1];
}
else if(i==n){
sum=sa[0]-pb[n-1];
}
else sum=sa[n-npa]+sb[m-npb]-pa[nna-1]-pb[nnb-1];
ans=max(sum,ans);
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
while (t--)
{
mrinfamous();
}
return 0;
}
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while (t--) {
ll n, f, a, b;
cin >> n >> f >> a >> b;
vector<ll>v(n, 0);
for (int i = 0; i < n; i++)
cin >> v[i];
// difference of consecutive dekh le. loss agar jyada hai ton swtich off kar dekh
// f hai charge
ll prev = 0;
for (int i = 0; i < n; i++) {
ll lst = 0;
if (i)
lst = v[i - 1];
ll dif = v[i] - lst;
ll cur = min(dif * a, b);
f -= cur;
}
if (f > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n;
string a,b;
cin>>n>>a>>b;
int cur1=0,cur2=0;
for(int i=0;i<n;i++){
if(a[i]==b[i])
continue;
if(a[i]=='0')
cur1++;
else
cur2++;
}
int ans=max(cur1,cur2);
cout<<ans<<endl;
}
return 0;
}
