Educational Codeforces Round 158 (Rated for Div. 2)
A
EDU的题总是感觉写起来怪怪的
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a[101];
void solve(){
int n,x;
cin>>n>>x;
int ans=0;
for(int i=1;i<=n;i++) cin>>a[i];
a[++n]=x;
ans=2*(x-a[n-1]);
for(int i=1;i<=n;i++){
int cnt=a[i]-a[i-1];
ans=max(ans,cnt);
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
B
.不会写,我是傻呗
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10;
int c[N];
void solve(){
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;i++){
cin>>c[i];
ans+=max(0ll,c[i]-c[i-1]);
}
cout<<ans-1<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
C
让最大值和最小值相等就行了。
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10;
int a[N];
int n;
void solve(){
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
int l=*min_element(a,a+n);
int r=*max_element(a,a+n);
vector<int> ans;
while(l!=r){
r = l + r >> 1;
ans.push_back(l);
}
cout<<ans.size()<<endl;
if(ans.size()<=n){
for(auto u:ans) cout<<u<<" ";
if(ans.size()) cout<<endl;
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
D
感觉比B C简单,虽然我写半天
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 3e5 + 10;
int a[N];
int b[N],c[N];
int n;
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i]+n-i;
c[i]=a[i]+i-1;
}
for(int i=1;i<=n;i++) b[i] = max(b[i],b[i-1]);
for(int i=n;i>=1;i--) c[i] = max(c[i],c[i+1]);
int ans=1e18;
for(int i=1;i<=n;i++) ans=min(ans,max({a[i],b[i-1],c[i+1]}));
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
}
- Educational Codeforces Round Rated 158educational codeforces round rated educational codeforces round 158 round codeforces rated based educational codeforces round 151 rated 158 div for construction educational codeforces round educational codeforces round 147 cf-educational educational codeforces round educational codeforces contest round educational codeforces monsters round