tyvjP2065 「Poetize10」封印一击

链接:http://www.tyvj.cn/p/2065

题意:中文题。。

分析:很显然我们将E定在一个端点处是最优的。定在哪呢?扫一遍咯,同时用两个标记标记E前面的左端点个数和右端点个数和一个E后面的左端点总和sum即可。记得ans和sum都要用long long 即可。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int MAX=151;
const int MOD=1000007;
const int MOD1=100000007;
const int MOD2=100000009;
const int INF=2100000000;
const double EPS=0.00000001;
typedef long long ll;
typedef unsigned long long ull;
int 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;
}
struct node {
    int b,w;
}a[2*N];
int cmd(node x,node y) {
    if (x.w!=y.w) return x.w<y.w;
    return x.b<y.b;
}
int main()
{
    int i,n,l,r,k=0,whe;
    ll sum=0,ans;
    scanf("%d", &n);
    for (i=1;i<=n;i++) {
        scanf("%d%d", &l, &r);
        sum+=(ll)l;
        k++;a[k].b=0;a[k].w=l;
        k++;a[k].b=1;a[k].w=r;
    }
    sort(a+1,a+k+1,cmd);
    ans=whe=0;l=0;r=0;
    for (i=1;i<=k;i++) {
        if ((ll)(l-r)*a[i].w+sum>ans) {
            whe=a[i].w;ans=(ll)(l-r)*a[i].w+sum;
        }
        if (a[i].b) r++;
        else { l++;sum-=a[i].w; }
    }
    printf("%d %lld\n", whe, ans);
    return 0;
}

/*
2
5 10
20 25
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值