"Poetize10" Seal

Source: Internet
Author: User
Description descriptionnescafe consists of n elements (numbered 1 ~ N), the I element has a seal interval [ai, BI]. When the seal strength E is smaller than that of AI, this element will obtain the seal energy of AI; when the seal strength E is between AI and Bi, this element will obtain the seal energy of E; when the seal strength E is greater than Bi, the element will be damaged and thus cannot obtain any seal energy. Now the Holy Lord applepi wants to select the appropriate E, so that the total energy obtained by the seal is as high as possible. For the final blow of the seal to be as perfect as possible, please write a program to help him calculate it! Question:
First, discretization is required. Then, the difference can be used to calculate the total score of <a [I] Out of the interval. Then, the difference can be used to calculate the number of times each vertex is covered by the interval, and then the statistics are made.
Code:
 1 #include<cstdio> 2  3 #include<cstdlib> 4  5 #include<cmath> 6  7 #include<cstring> 8  9 #include<algorithm>10 11 #include<iostream>12 13 #include<vector>14 15 #include<map>16 17 #include<set>18 19 #include<queue>20 21 #include<string>22 23 #define inf 100000000024 25 #define maxn 100000026 #define maxm 500+10027 28 #define eps 1e-1029 30 #define ll long long31 32 #define pa pair<int,int>33 34 #define for0(i,n) for(int i=0;i<=(n);i++)35 36 #define for1(i,n) for(int i=1;i<=(n);i++)37 38 #define for2(i,x,y) for(int i=(x);i<=(y);i++)39 40 #define for3(i,x,y) for(int i=(x);i>=(y);i--)41 42 #define mod 100000000743 44 using namespace std;45 46 inline int read()47 48 {49 50     int x=0,f=1;char ch=getchar();51 52     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}53 54     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}55 56     return x*f;57 58 }59 struct rec{ll x,y;}b[maxn];60 ll n,a[maxn],s[3][maxn],c[maxn];61 inline bool cmp(rec a,rec b){return a.x<b.x;}62 63 int main()64 65 {66 67     freopen("input.txt","r",stdin);68 69     freopen("output.txt","w",stdout);70 71     n=read();72     for1(i,n)a[(i<<1)-1]=read(),a[i<<1]=read();73     for1(i,n<<1)b[i].x=a[i],b[i].y=i;74     sort(b+1,b+2*n+1,cmp);75     int tot=0;76     for1(i,n<<1)77     {78         if(i==1||b[i].x!=b[i-1].x)tot++;79         a[b[i].y]=tot;c[tot]=b[i].x;80     }81     for1(i,n)82     {83        int l=a[(i<<1)-1],r=a[i<<1];84        s[1][1]+=c[l];s[1][l]-=c[l];85        s[2][l]++;s[2][r+1]--;86     }87     int ans=0;88     for1(i,tot+1)89     {90         s[1][i]+=s[1][i-1];s[2][i]+=s[2][i-1];91         if(s[1][i]+s[2][i]*c[i]>s[1][ans]+s[2][ans]*c[ans])ans=i;92     }93     printf("%lld %lld\n",c[ans],s[1][ans]+s[2][ans]*c[ans]);94     return 0;95 96 }
View code

 

"Poetize10" Seal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.