codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题

B. Photo to Remember

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/522/problem/B

Description

One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.

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.

Sample Input

3
1 10
5 5
10 1

Sample Output

75 110 60

HINT

 

题意

 每一个人都有一个体积,然后问你,抛去这个人之后,用一个多大的矩形,才能把剩下的人给包住

题解:

记录一下除了这个数的长的最大值,然后用一个前缀和来维护一下宽就好了

代码:

 

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
/*

inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
*/
//**************************************************************************************
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}

int a[maxn];
int b[maxn];
int main()
{
    int flag2=0;
    int n=read();
    int ma=0;
    int ma2=0;
    int sum=0;
    for(int i=0;i<n;i++)
        a[i]=read(),b[i]=read(),sum+=a[i];
    for(int i=0;i<n;i++)
        ma=max(ma,b[i]);
    int flag=0;
    for(int i=0;i<n;i++)
        if(b[i]==ma)
        {
            flag++;
            flag2=i;
        }

    if(flag==1)
    {
        for(int i=0;i<n;i++)
            if(b[i]!=ma)
                ma2=max(ma2,b[i]);

    }
    if(flag==1)
    {
        for(int i=0;i<n;i++)
        {
            if(i==flag2)
                printf("%d ",ma2*(sum-a[i]));
            else
                printf("%d ",ma*(sum-a[i]));
        }
    }
    else
    {
        for(int i=0;i<n;i++)
            printf("%d ",ma*(sum-a[i]));
    }
}

 

posted @ 2015-04-20 23:01  qscqesze  阅读(401)  评论(0编辑  收藏  举报