1 条题解

  • 0
    @ 2025-3-22 10:47:39

    不使用数组,注意到需要加水的水量等于n个杯子都装最大水量再减去目前杯子中的总水量\

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n; cin>>n;
    	int maxn=-1,sum=0;
    	for(int i=1;i<=n;i++){
    		int x;
    		cin>>x;
    		maxn=max(maxn,x);
    		sum+=x;
    	}
    	cout<<maxn*n-sum;
    	return 0;
    }
    
    • 1

    信息

    ID
    1081
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    2
    已通过
    1
    上传者