Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
思路:找出最高和次高,求出宽度总和,第i个是最高就用次高,不是就是最高,然后乘上宽度总和-wi
代码:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <cctype>
#include <sstream>
#define INF 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
typedef long long LL;
using namespace std;
const int maxn = 2e5 + 5;
const LL mod = 1e9+7;
int n,w[maxn],h[maxn],Max=0,Maxc=0,H,W;
int main()
{
//freopen ("in.txt","r",stdin);
scanf ("%d",&n);
for (int i=0;i<n;i++) {
scanf ("%d%d",&w[i],&h[i]);
W+=w[i];
if (h[i]>=Max){
Maxc=Max;
Max=h[i];
}
else if (h[i]<Max&&h[i]>Maxc){
Maxc=h[i];
}
}
int ans;
for (int i=0;i<n;i++){
if (h[i]==Max) ans=Maxc*(W-w[i]);
else ans=Max*(W-w[i]);
printf ("%d ",ans);
}
printf ("\n");
return 0;
}