• Educational Codeforces Round 69 (Rated for Div. 2) A B C D


    Educational Codeforces Round 69 (Rated for Div. 2)

    A

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e5+100;
    
    int t;
    int n;
    int a[N];
    int main(){
    	cin >> t;
    	while(t--){
    		cin >> n;
    		for(int i=0;i<n;i++){
    			cin >> a[i];
    		}
    		sort(a,a+n);
    		int h=min(a[n-1],a[n-2]);
    		if(h<2){
    			cout << "0
    ";
    		}
    		else cout << min(n-2,h-1) << "
    ";
    	}
    	return 0;
    }
    

      B

    数组必须先增后减,或者单调递增,单调递减

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 2e5+100;
    int n;
    int a[N];
    int main(){
    	cin >> n;
    	for(int i = 0; i < n; i++){
    		cin >> a[i];
    	}
    	int i;
    	for(i = 1; i < n; i++){
    		if(a[i] < a[i-1])
    			break;
    	}
    	int flag = 1;
    	for(i=i+1;i<n;i++){
    		if(a[i] > a[i-1]){
    			flag = 0;
    		}
    	}
    	if(flag) cout << "YES
    ";
    	else cout << "NO
    ";
    	return 0;
    }
    

      C 

    要使数组分成k份,必须选择k-1个间隔,间隔差值越大,最后的每个区间max-min的和越小

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 3e5+100;
    
    int n,k;
    int a[N];
    int p[N];
    bool cmp(int x,int y){
    	return x>y;
    }
    int main(){
    	cin >> n >> k;
    	for(int i = 0; i < n; i++){
    		cin >> a[i];
    	}
    	for(int i=1; i < n; i++){
    		p[i] = a[i] - a[i-1];
    	}
    	sort(p+1,p+n,cmp);
    	ll res = 0;
    	for(int i=1; i<=k-1;i++){
    		res += p[i];
    	}
    	cout << a[n-1]- a[0]-res << "
    ";
    	return 0;
    }
    

      D

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=3e5+100;
    int n,m,k;
    int a[N];
    ll sum[N];
    ll dp[N];
    int main(){
        cin >> n >> m >> k;
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            dp[i] = max(0, a[i]-k);
            sum[i] = sum[i-1] + a[i];
        }
        ll res = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(i-j >= 0){
                    dp[i] = max(dp[i], dp[i-j]-k + sum[i]-sum[i-j]);
                    res = max(res,dp[i]);
                }
            }
        }
        cout << res << endl;
    }
    

      

  • 相关阅读:
    SpringBoot-redis-session
    设计模式总结
    linux 查看磁盘信息
    MAC配置JAVA环境变量
    mysql设计规范二
    mysql设计规范一
    Alibaba 镜像
    ELK之Logstash配置文件详解
    Docker 搭建 ELK 读取微服务项目的日志文件
    SpringBoot 读取配置文件的值 赋给静态变量
  • 原文地址:https://www.cnblogs.com/YJing814/p/11244151.html
Copyright © 2020-2023  润新知