当前位置: 首页 > news >正文

手表网站建设竞价推广课程

手表网站建设,竞价推广课程,雅诗兰黛网络营销策划方案,军事新闻2023CF1574C Slay the Dragon 题解题目链接字面描述题面翻译题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1提示代码实现题目 链接 https://www.luogu.com.cn/problem/CF1574C 字面描述 题面翻译 给定长度为 nnn 的序列 aaa,mmm 次询问,每次询…

CF1574C Slay the Dragon 题解

  • 题目
    • 链接
    • 字面描述
      • 题面翻译
      • 题目描述
      • 输入格式
      • 输出格式
      • 样例 #1
        • 样例输入 #1
        • 样例输出 #1
      • 提示
  • 代码实现

题目

链接

https://www.luogu.com.cn/problem/CF1574C

字面描述

题面翻译

给定长度为 nnn 的序列 aaammm 次询问,每次询问包含两个参数 x,yx,yx,y,你可以给序列任意位置 +1+1+1,最后你需要找出一个位置 ppp ,满足

  • ap≥xa_p\ge xapx
  • ∑i=1nai[i≠p]≥y\displaystyle\sum_{i=1}^n a_i[i\not= p] \ge yi=1nai[i=p]y

最小化 +1+1+1 次数,输出其次数。

限制2≤n≤2×105,1≤m≤2×105,1≤ai,x≤1012,1≤y≤10182\le n\le2\times 10^5,1\le m\le 2\times10^5,1\le a_i,x\le 10^{12},1\le y\le 10^{18}2n2×105,1m2×105,1ai,x1012,1y1018

Translated by 飞丞

题目描述

Recently, Petya learned about a new game “Slay the Dragon”. As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of $ n $ heroes, the strength of the $ i $ -th hero is equal to $ a_i $ .

According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon’s defense is equal to $ x $ , then you have to send a hero with a strength of at least $ x $ to kill it. If the dragon’s attack power is $ y $ , then the total strength of the heroes defending the castle should be at least $ y $ .

The player can increase the strength of any hero by $ 1 $ for one gold coin. This operation can be done any number of times.

There are $ m $ dragons in the game, the $ i $ -th of them has defense equal to $ x_i $ and attack power equal to $ y_i $ . Petya was wondering what is the minimum number of coins he needs to spend to defeat the $ i $ -th dragon.

Note that the task is solved independently for each dragon (improvements are not saved).

输入格式

The first line contains a single integer $ n $ ( $ 2 \le n \le 2 \cdot 10^5 $ ) — number of heroes.

The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 10^{12} $ ), where $ a_i $ is the strength of the $ i $ -th hero.

The third line contains a single integer $ m $ ( $ 1 \le m \le 2 \cdot 10^5 $ ) — the number of dragons.

The next $ m $ lines contain two integers each, $ x_i $ and $ y_i $ ( $ 1 \le x_i \le 10^{12}; 1 \le y_i \le 10^{18} $ ) — defense and attack power of the $ i $ -th dragon.

输出格式

Print $ m $ lines, $ i $ -th of which contains a single integer — the minimum number of coins that should be spent to defeat the $ i $ -th dragon.

样例 #1

样例输入 #1

4
3 6 2 3
5
3 12
7 9
4 14
1 10
8 7

样例输出 #1

1
2
4
0
2

提示

To defeat the first dragon, you can increase the strength of the third hero by $ 1 $ , then the strength of the heroes will be equal to $ [3, 6, 3, 3] $ . To kill the dragon, you can choose the first hero.

To defeat the second dragon, you can increase the forces of the second and third heroes by $ 1 $ , then the strength of the heroes will be equal to $ [3, 7, 3, 3] $ . To kill the dragon, you can choose a second hero.

To defeat the third dragon, you can increase the strength of all the heroes by $ 1 $ , then the strength of the heroes will be equal to $ [4, 7, 3, 4] $ . To kill the dragon, you can choose a fourth hero.

To defeat the fourth dragon, you don’t need to improve the heroes and choose a third hero to kill the dragon.

To defeat the fifth dragon, you can increase the strength of the second hero by $ 2 $ , then the strength of the heroes will be equal to $ [3, 8, 2, 3] $ . To kill the dragon, you can choose a second hero.

代码实现

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxn=2e5+10;
int n,m;
ll tot;
ll a[maxn];
int main(){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);tot+=a[i];}sort(a+1,a+n+1);scanf("%d",&m);while(m--){ll x,y;scanf("%lld%lld",&x,&y);if(tot<x+y){if(a[1]>x){printf("%lld\n",y-(tot-a[1]));continue;}int l=1,r=n;while(l<=r){int mid=l+r>>1;if(a[mid]>x)r=mid-1;else if(a[mid]<x)l=mid+1;else break;}int op=l+r>>1;if(y<=tot-a[op])printf("%lld\n",x-a[op]);else printf("%lld\n",x-a[op]+y-(tot-a[op]));continue;}else{if(a[1]>x){if(y>tot-a[1])printf("%lld\n",y-(tot-a[1]));else printf("0\n");continue;}int l=1,r=n;while(l<=r){int mid=l+r>>1;if(a[mid]>x)r=mid-1;else if(a[mid]<x)l=mid+1;else break;}int op=l+r>>1;int op1=op+1;if(tot==x+y){if(op1<=n)printf("%lld\n",min(x-a[op],a[op1]-x));else printf("%lld\n",x-a[op]);}else{if(y<=tot-a[op1]){if(op1<=n)printf("0\n");else printf("%lld\n",x-a[op]);}else {if(op1<=n)printf("%lld\n",min(x-a[op],y-(tot-a[op1])));else printf("%lld\n",x-a[op]);}}}}return 0;
}
http://www.zhongyajixie.com/news/985.html

相关文章:

  • 东莞南城网站开发公司怎么样创建网站
  • 深圳珠宝网站建设火星时代教育培训机构官网
  • 微信旧版本下载seoul是什么国家
  • 网站文案编辑怎么做seo模拟点击软件源码
  • 做网站找模板南宁seo公司
  • 营销型网站的目标是品牌营销策略研究
  • 做网站怎么挣钱网上售卖平台有哪些
  • 青岛网站建设方案策划日结app推广联盟
  • 做软装有什么网站找图片网络营销意思
  • 95598网站服务建设站内关键词排名优化软件
  • 小程序 开发公司自媒体seo是什么意思
  • 用vue做商城网站常用的jsgoogle chrome浏览器
  • 天津艺匠做网站怎么样京津冀协同发展
  • 做商业网站的服务费维护费泰州seo网站推广
  • 找人做seo要给网站程序推广之家app
  • 郫县做网站新闻投稿
  • 软件公司找项目seo工具包括
  • n怎样建立自己的网站百度app旧版本下载
  • 如何申请网站域名国际新闻最新消息2022
  • 贵阳网站制作免费电子商务网站设计方案
  • 自己建设企业网站口碑营销策略
  • 深圳seo优化外包公司网站优化的关键词
  • 有域名自己怎么做网站搜索引擎优化的作用
  • 淘宝客网站如何做SEOseo一般包括哪些内容
  • 哪里可以找到做网站的搜索竞价排名
  • 企业内部网站模板优化大师怎么卸载
  • 网站建设方案文本模板网络推广 公司 200个网站
  • 外贸企业网站 facebook优秀企业网站模板
  • 专业行业网站建站报价竞价推广营销
  • 免费网站建设策划app线上推广是什么工作