Problem - A - Codeforces
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=55;
int a[N];
int n,x;
void solve() {
cin>>n>>x;
for(int i=1;i<=n;i++) cin>>a[i];
a[n+1]=1000;
int ans=0;
int pos=lower_bound(a+1,a+1+n+1,x)-a;
pos--;
// cout<<pos<<endl;
for(int i=1;i<=pos;i++){
ans=max(ans,a[i]-a[i-1]);
}
ans=max(ans,2*(x-a[pos]));
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}
Problem - B - Codeforces
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
int n;
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int ans=0;
ans+=a[1]-1;
for(int i=2;i<=n;i++){
if(a[i]>=a[i-1]) ans+=a[i]-a[i-1];
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}
Problem - C - Codeforces
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
int n;
void solve() {
cin>>n;
int maxn=0;
int minn=2e9;
for(int i=1;i<=n;i++) cin>>a[i],maxn=max(maxn,a[i]),minn=min(minn,a[i]);
if(maxn==minn){
cout<<0<<endl;
return;
}
int ans=0;
vector<int>c;
while(maxn!=minn+1){
ans++;
if(minn%2){
maxn++;
minn++;
c.push_back(1);
}
else{
c.push_back(0);
}
maxn/=2;
minn/=2;
if(maxn==0) break;
}
if(maxn==minn+1){
cout<<ans+1<<endl;
if(ans+1<=n){
for(auto v:c) cout<<v<<' ';
if(minn%2==0) cout<<2<<endl;
else cout<<1<<endl;
}
}
else{
cout<<ans<<endl;
if(ans<=n){
for(auto v:c) cout<<v<<' ';
cout<<endl;
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}