Codeforces|Leetcode|Codechef free solutions
Open in Telegram
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.
Show more4 317
Subscribers
No data24 hours
-137 days
-5230 days
Posts Archive
#include <iostream>
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define pb push_back
void sol(){
int n,e;
cin>>n>>e;
vector<int> v(n);
for(auto &val:v) cin>>val;
v[0]+=e;
int ind = 0,m = v[0];
for(int i = 0;i<v.size();i++){
Ā Ā if(m<v[i]){
Ā Ā Ā Ā m = v[i];
Ā Ā Ā Ā ind = i;
Ā Ā }
}
int pre = 0;
vector<int> ans;
for(auto i = 0;i<v.size();i++){
Ā Ā int val = v[i];
Ā Ā pre+=val;
Ā Ā if(i==ind){
Ā Ā Ā Ā ans.push_back(0);
Ā Ā }
Ā Ā else{
Ā Ā Ā Ā
Ā Ā Ā Ā if(pre>=m){
Ā Ā Ā Ā Ā Ā ans.push_back(i);
Ā Ā Ā Ā }
Ā Ā Ā Ā else{
Ā Ā Ā Ā Ā Ā ans.push_back(i+1);
Ā Ā Ā Ā }
Ā Ā Ā Ā
Ā Ā }
Ā Ā
Ā Ā
}
for(auto &val:ans){
Ā Ā cout<<val<<" ";
}
cout<<endl;
Ā return;
}
signed main()
{
Ā
Ā int test;
Ā cin>>test;
Ā while(test--){
Ā Ā Ā sol();
Ā }
Ā Ā
Ā Ā Ā return 0;
}
New target šÆ
Will share D on 4215+ subscribersš
Share this channel with your friends will upload more free codes in the channelšš
#include <iostream>
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define pb push_back
void sol(){
int n,k;
cin>>n>>k;
vector<int> ans;
int sum = 0;
for(int i = 1;i<=n;i++){
Ā Ā sum+=abs(i - (n-i+1));
Ā Ā ans.push_back(i);
Ā // cout<<i<<endl;
}
if(k%2==1||sum<k){
Ā Ā cout<<"NO"<<endl;
}
else{
Ā Ā cout<<"YES"<<endl;
Ā Ā int ind = 0;
Ā Ā int N = n;
Ā Ā while((k)>(N-1)*2){
Ā Ā Ā // cout<<k<<" "<<ind<<endl;
Ā Ā Ā Ā swap(ans[ind],ans[n-ind-1]);
Ā Ā Ā Ā k-=(N-1)*2;
Ā Ā Ā Ā N-=2;
Ā Ā Ā Ā ind++;
Ā Ā }
Ā Ā
Ā Ā
Ā Ā k/=2;
Ā Ā
Ā Ā swap(ans[ind],ans[ind+k]);
Ā Ā
Ā Ā
Ā Ā int cal = 0;
Ā Ā for(auto i = 0;i<ans.size();i++){
Ā Ā Ā Ā cal+=abs(ans[i] - i-1);
Ā Ā Ā Ā cout<<ans[i]<<" ";
Ā Ā }
Ā Ā cout<<endl;
Ā // cout<<cal<<endl;
Ā Ā
}
Ā return;
}
signed main()
{
Ā
Ā int test;
Ā cin>>test;
Ā while(test--){
Ā Ā Ā sol();
Ā }
Ā Ā
Ā Ā Ā return 0;
}
#include <iostream>
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define pb push_back
void sol(){
int n,a,b;
cin>>n>>a>>b;
if(b<a){
Ā Ā cout<<n*a<<endl;
}
else{
Ā Ā
Ā Ā Ā int x = min(n,b - a);
Ā Ā Ā int y = n - x;
Ā Ā Ā int c = b-x;
Ā Ā Ā
Ā Ā Ā int ans = y*a + (b*(b+1)/2) - (c*(c+1)/2);
Ā Ā Ā
Ā Ā Ā cout<<ans<<endl;
Ā Ā Ā
Ā Ā
}
Ā return;
}
signed main()
{
Ā
Ā int test;
Ā cin>>test;
Ā while(test--){
Ā Ā Ā sol();
Ā }
Ā Ā
Ā Ā Ā return 0;
}
Dm me today for any oa slots, today I am free for any coding rounds.
