-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2703.cpp
More file actions
46 lines (46 loc) · 733 Bytes
/
2703.cpp
File metadata and controls
46 lines (46 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
struct rec{
int w,h;
};
bool bj(struct rec &t1,struct rec &t2){
return t1.w>t2.w;
}
int main(){
int n;
int wt,ht3,ht4,ht1,ht2,i;
struct rec t;
int res;
vector<struct rec> jx;
cin>>n;
while(n!=-1){
jx.clear();
while(n--){
cin>>t.w>>t.h;
jx.push_back(t);
}
sort(jx.begin(),jx.end(),bj);
ht4=0;
ht3=jx[0].w;
i=0;
res=0;
while(i<jx.size()){
ht1=ht2=0;
wt=jx[i].w;
while(wt==jx[i].w&&i<jx.size()){
if(jx[i].h>ht1){ht2=ht1;ht1=jx[i].h;}
else if(jx[i].h>ht2) ht2=jx[i].h;
i++;
}
if(ht2==0)ht2=ht3;
res+=(ht2+ht1-ht3-ht4)*wt;
ht3=ht1;
ht4=ht2;
}
cout<<res<<endl;
cin>>n;
}
return 0;
}