题目描述
e,自己去读读
思路
(暴力枚举) $O(n)$
计算每一次的结果,只需要找到除开当前牛的总长度和除开当前牛的最高值即可,故保存一个所有牛的总长度,保存一个高度的最高值和次高值(最高可能等于次高)
C++ 代码
#include<iostream>
using namespace std;
const int mxn=2e5+10;
int n;
int w[mxn],h[mxn];
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
int max_h=0,second_h=0,sum_w=0;//高度最高值,次高值,总长度
for(int i=1;i<=n;++i){
cin>>w[i]>>h[i];
sum_w+=w[i];
second_h=max(second_h,h[i]);
if(second_h>max_h)swap(second_h,max_h);
}
int res=0;
for(int i=1;i<=n;++i){
res=sum_w-w[i];
if(max_h!=h[i])cout<<res*max_h<<' ';
else cout<<res*second_h<<' ';
}
return 0;
}