797F - Mice and Holes

思路:

  XXYXX

代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 5005
#define ll long long struct HoleType {
ll x,c;
};
struct HoleType hole[maxn]; ll n,m,mice[maxn],s[maxn],sum,dp[maxn][maxn],que[maxn]; inline void in(ll &now)
{
ll if_z=;now=;
char Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} bool cmp(HoleType aa,HoleType bb)
{
return aa.x<bb.x;
} int main()
{
in(n),in(m);
for(ll i=;i<=n;i++) in(mice[i]);
for(ll i=;i<=m;i++) in(hole[i].x),in(hole[i].c),sum+=hole[i].c;
if(sum<n)
{
printf("-1\n");
return ;
}
sort(mice+,mice+n+),sort(hole+,hole+m+,cmp);
memset(dp,0x7f,sizeof(dp)),dp[][]=;
for(ll i=;i<=m;i++)
{
ll head=,tail=-;
for(ll j=;j<=n;j++) s[j]=s[j-]+abs(hole[i].x-mice[j]);
for(ll j=;j<=n;j++)
{
while(head<=tail&&que[head]<j-hole[i].c) head++;
while(tail>=head&&dp[i-][j]-s[j]<=dp[i][que[tail]]-s[que[tail]]) tail--;
que[++tail]=j,dp[i][j]=dp[i-][que[head]]-s[que[head]]+s[j];
}
}
cout<<dp[m][n];
return ;
}

AC日记——Mice and Holes codeforces 797f的更多相关文章

  1. Mice and Holes CodeForces - 797F

    Mice and Holes CodeForces - 797F 题意:有n只老鼠和m个洞,都在一个数轴上,老鼠坐标为x[1],...,x[n],洞的坐标为p[1],...,p[m],每个洞能容纳的老 ...

  2. AC日记——Dynamic Problem Scoring codeforces 807d

    Dynamic Problem Scoring 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <io ...

  3. AC日记——Sign on Fence Codeforces 484e

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  4. AC日记——Sagheer, the Hausmeister codeforces 812b

    812B - Sagheer, the Hausmeister 思路: 搜索: 代码: #include <cstdio> #include <cstring> #includ ...

  5. AC日记——Sagheer and Crossroads codeforces 812a

    812A - Sagheer and Crossroads 思路: 模拟: 代码: #include <cstdio> #include <cstring> #include ...

  6. AC日记——Is it rated? codeforces 807a

    Is it rated? 思路: 水题: 代码: #include <cstdio> #include <cstring> using namespace std; ],b[] ...

  7. Ac日记——Distances to Zero codeforces 803b

    803B - Distances to Zero 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <i ...

  8. AC日记——Roma and Poker codeforces 803e

    803E - Roma and Poker 思路: 赢或输或者平的序列: 赢和平的差的绝对值不得超过k: 结束时差的绝对值必须为k: 当“?”时可以自己决定为什么状态: 输出最终序列或者NO: dp( ...

  9. AC日记——Periodic RMQ Problem codeforces 803G

    G - Periodic RMQ Problem 思路: 题目给一段序列,然后序列复制很多次: 维护序列很多次后的性质: 线段树动态开点: 来,上代码: #include <cstdio> ...

随机推荐

  1. jsUnpacker

    EVAL function executeEval(){ let evalCodeElt = document.getElementById("eval_code"); let e ...

  2. 从事IT业一个8年老兵转行前的自我总结1——初爻

    现在,本人已离开这个呆了8年的软件行业了.回想自己从半路出家,从实施开始做起,最终在一家外企做项目经理PM结束了自己的软件职业生涯.从一张白纸的自学开始,做过项目实施,客户培训,拿过需求,开发,架构设 ...

  3. (原)App源码

    序) 人生就像卫生纸,有事没事少扯 前言) 最近偶尔和一位极客大牛聊了一次,这个极客在汇编的造诣算是相当高,不过野路子出来看不起各种规矩,因此是适合做个自己蒙头研究技术的极客男,不适合大型团队,不适合 ...

  4. 【The VC Dimension】林轩田机器学习基石

    首先回顾上节课末尾引出来的VC Bound概念,对于机器学习来说,VC dimension理论到底有啥用. 三点: 1. 如果有Break Point证明是一个好的假设集合 2. 如果N足够大,那么E ...

  5. HTTP响应码

    更详细的内容参考:https://baike.baidu.com/item/HTTP状态码/5053660?fr=aladdin 转载CSDN作者:ddhsea 的文章 https://blog.cs ...

  6. 你的第一个自动化测试:Selenium 自动化测试

    前言: 让你掌握自动化测试暂时脱离手工点点点,本章节让你掌握 Selenium 如何定位.判定.操作元素(实现业务逻辑) 一. 前期准备 1.准备以下工具 1.Selenium下载地址:立即下载 2. ...

  7. Pytest+allure+jenkins生成测试报告

    allure集成jenkins下载地址.下载相关版本的allure包 http://updates.jenkins-ci.org/download/plugins/allure-jenkins-plu ...

  8. python之路——网络编程

    一.楔子 你现在已经学会了写python代码,假如你写了两个python文件a.py和b.py,分别去运行,你就会发现,这两个python的文件分别运行的很好.但是如果这两个程序之间想要传递一个数据, ...

  9. [OpenCV] Ptr类模板

    1.C++泛型句柄类 我们知道在包含指针成员的类中,需要特别注意类的复制控制,因为复制指针时只复制指针中的地址,而不会复制指针指向的对象.这将导致当两个指针同时指向同一对象时,很可能一个指针删除了一对 ...

  10. leetcode_day03

    https://leetcode-cn.com/problems/container-with-most-water/ 题目:盛水最多的容器 给定 n 个非负整数 a1,a2,...,an,每个数代表 ...