C. Little Girl and Maximum Sum Codeforces Round #169 (Div. 2)

http://codeforces.com/contest/276/problem/C  原题连接

 

解题说明:题目的意思是有若干对区间和的查询,问如何重组数组使查询结果的和最大。

我的解法就是将对应的频率排序之后在求(求频率那里需要点思维嘻嘻

直接贴代码了

#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 4e5 + 40;
typedef long long ll;
const int  inf = 0x3fffff;
void read(ll &x) {
    char ch; bool flag = 0;
    for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
    for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
    x *= 1 - 2 * flag;
}

ll val[maxn];
int vis[maxn];

struct inof{
   ll  l;
   bool flag;
}fuck[maxn];

bool cmp(inof a,inof b)
{
    return a.l<b.l;
}
int res[maxn];
int main() {
    ll n,m;
    memset(vis,0,sizeof(vis));
    read(n),read(m);
    for(int i=1;i<=n;i++){
        read(val[i]);
    }
    int top = 0;
    while(m--){
       // ll l,r;
        read(fuck[top].l);
        fuck[top].flag=1;
        top++;
        read(fuck[top].l);
        fuck[top].l++;
        fuck[top].flag=0;
        top++;
        //read(l),read(r);
        //vis[l]++,vis[r+1]--;
    }
    sort(fuck,fuck+top,cmp);
    int sub = 0;
    int maxx = 0;
    for(int i=0;i<top;i++)
    {
        if(i)vis[sub]+=fuck[i].l-fuck[i-1].l;
        if(fuck[i].flag)sub++;
        else sub--;
        maxx=max(maxx,sub);
    }
    ll ans = 0;
    sort(val+1,val+n+1);
  //  sort(vis,vis+maxx+1);
    int temp = n;
    for(int i=maxx;i>=0;i--)
    {
        if(vis[i])
        {
            while(temp>=1&&vis[i])vis[i]--,ans+=val[temp]*i,temp--;
        }
        if(temp==0)break;
    }
    cout<<ans<<endl;
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/DreamKill/p/9427745.html

matlab电容式传感器仿真,差动电容式位移传感器的仿真研究 设计了一种差动电容式位移传感器,主要对传感器的数学模型及电容检测电路进行了仿真研究。其中检测电路设计主要包括正弦激励电路、转换桥路、信号放大电路、精密整流电路和滤波电路。最后利用Matlab/SimurFnk软件对所设计的系统进行仿真,并分析了传感器性能。仿真研究表明,传感器及其检测电路具有合理性,测量范围内具有很好的线性度。0|| I≯ lat on ii{差动容尊翩’亘研发注:湖南省教育厅资... 阅读详情

相关推荐

STM32H743实战(三)-- 时钟系统配置

本文详细讲解了STM32H743时钟系统的配置方法,重点解析了为何选择400MHz而非理论极限480MHz作为稳定运行的主频。通过STM32CubeIDE环境,手把手指导如何从外部晶振配置、电源电压设置到PLL锁相环参数调整,最终实现稳定可靠的400MHz系统时钟,并提供了代码验证与常见问题排查指南。

weixin_29164185的博客 346

1076 Forwards on Weibo (Life is so fucking hard, bring a brother to tears)

Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a...

qq_43813697的博客 2568

fuck girl magazines+18(3)

fuck girl magazines+18(3)病毒,可以直接运行,插入到你电脑你的U盘上的文件全部变成快捷方式!!!小心使用(删除不了,可以用策略组解决问题)

watch watch watch the video! I got almost addicted. Oh what a fuck!!!!

http://v.huya.com/play/574329.html#relate_vid=570467    转载于:https://www.cnblogs.com/hualiu0/p/5115217.html

weixin_33713503的博客 6708

The use of fuck: A sociolinguistic approach to the usage of fuck in the BNC and blog authorship 【翻译】

Acknowledgments Thank you to my advisor, Veronica, for allowing me to write and research this controversial topic. Also thank you to my family for supporting me throughout my education, and my friends...

hongfu951的专栏 2642

hd_Hot girl with cool car

#include &lt;cmath&gt; #include &lt;stdlib.h&gt; #include &lt;iostream&gt; using namespace std; const double PI = acos(-1.0); int main ( int argc, char *argv[] ) { double r,w,...

tubaluer 2762

Codeforces Round #169 (Div. 2) C. Little Girl and Maximum Sum 差分问题

The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you’ve got an array of n elements (the elements of the array are indexed starting f...

loooooog的博客 259

Codeforces Round #169 (Div. 2) C. Little Girl and Maximum Sum(差分)

有 n 个数,m 次询问,每次询问将区间 [l,r] 内的数求和,现在要求重排数组,使得这 m 此询问的求和总值最大,输出最大值 每给出区间 [l,r],那么当前点的贡献+1,最大数*最大贡献即为贪心策略 const int N=2e5+5; int n,m; int i,j,k; int a[N]; int d[N]; int main() { while(~sdd(n,m)){ for(int i=1;i<=n;i...

C_Dreamy的博客 391

Codeforces Round #169 (Div. 2)C. Little Girl and Maximum Sum(贪心/排序)

传送门 Description The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array ofnelements (the elements of the array ar...

weixin_30359021的博客 116

Codeforces Round #169 (Div. 2) C. Little Girl and Maximum Sum(线段树区间更新)

C. Little Girl and Maximum Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The little girl loves the problems o...

weixin_33795093的博客 173

Codeforces Round 169 (Div. 2)C. Little Girl and Maximum Sum(差分、贪心)

注意空间,空间开小了在cf上可能tletletle对着种多次区间操作,一次查询要考虑一下差分,很多时候用不到那么复杂的数据结构就能解决问题。

cx1的博客 985

Codeforces Round #677 (Div. 3)部分题解

A - Boring ApartmentsB - Yet Another BookshelfC - Dominant PiranhaD - Little Girl and Maximum Sum 差分 贪心 前缀和

m0_64524852的博客 295

FUCK U

<br />FFFFFFFFFFFFFFFFFFFFF

downfile911的专栏 1081

Fuck Google! Fuck Google Play!! Fuck Google Play App Signing!!!!!!

草他妈的 Google Play App Signing! 真tm的是个弱智功能!!! mmp

璀璨灯火一行梦 1万+

Eighth season fifteenth episode,Joey fell in love with Rachel??????

[Scene: Central Perk. Rachel is getting a cup of coffee as Joey and Phoebe enter and sit down.] Phoebe: Oh! Hey, Rach! Rachel: Hi! Hey, Happy Valentine's Day! Phoebe: Oh, you, too. Joey: Hey, so, uh, how's it going living over at Ross'? Rachel: It's good.

xiyangxia666hui的博客 3万+

Forgetful Girl

There is such a girl born after 1980,sunny,outgoing,straightforward,helpful,even though her appearance seems like not so be impressed Maybe just for this,so many people no matter the females or males

ANLJF的专栏 1826

The strip's most beautiful gril,rendezvous never a cover;

大道上最美丽的女孩,约会从来不需要理由 长虎牙的漂亮妹子 转载于:https://www.cnblogs.com/shihao316558512/archive/2013/04/09/9737054.html...

NickWei1994的专栏 836

Fuck work

IT 企业招聘新人喜欢要求工作经验,而衡量工作经验的标准跟ML标准 一样:时间越长越好,但如果你年龄超过35 岁了,一般来说就不行了。

刘佳迪的专栏 1651

Seventh season sixth episode,Joey and Ross are nap partners!!!!they hug for a nap!!!!!

7-6还木有发,3-6再说

xiyangxia666hui的博客 1920

AXI VIP配置interleaving[项目代码]

本文详细介绍了如何在AXI slave VIP中配置out of order read data和interleaved read data。对于out of order read data,需要设置read_data_reordering_depth属性,并可能重新定义SVT_AXI_MAX_READ_DATA_REORDERING_DEPTH宏。对于interleaved read data,需配置read_data_interleave_size属性,并设置enable_interleave为1以及interleave_pattern为RANDOM BLOCK。此外,文章还提供了相关的编译宏定义和逻辑代码示例,帮助用户实现所需的配置。

上一篇: A - Sliding Window POJ - 2823
下一篇: D. Vasiliy's Multiset 异或字典树
axian1654
博客等级 码龄10年 0粉丝 0原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值