中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

做企業(yè)網(wǎng)站建設(shè)下載百度app

做企業(yè)網(wǎng)站建設(shè),下載百度app,wdcp wordpress forbidden 403,免費(fèi)的推文制作網(wǎng)站CF1574C Slay the Dragon 題解題目鏈接字面描述題面翻譯題目描述輸入格式輸出格式樣例 #1樣例輸入 #1樣例輸出 #1提示代碼實(shí)現(xiàn)題目 鏈接 https://www.luogu.com.cn/problem/CF1574C 字面描述 題面翻譯 給定長(zhǎng)度為 nnn 的序列 aaa,mmm 次詢問(wèn),每次詢…

CF1574C Slay the Dragon 題解

  • 題目
    • 鏈接
    • 字面描述
      • 題面翻譯
      • 題目描述
      • 輸入格式
      • 輸出格式
      • 樣例 #1
        • 樣例輸入 #1
        • 樣例輸出 #1
      • 提示
  • 代碼實(shí)現(xiàn)

題目

鏈接

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

字面描述

題面翻譯

給定長(zhǎng)度為 nnn 的序列 aaammm 次詢問(wèn),每次詢問(wèn)包含兩個(gè)參數(shù) x,yx,yx,y,你可以給序列任意位置 +1+1+1,最后你需要找出一個(gè)位置 ppp ,滿足

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

最小化 +1+1+1 次數(shù),輸出其次數(shù)。

限制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.

代碼實(shí)現(xiàn)

#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://m.risenshineclean.com/news/60751.html

相關(guān)文章:

  • 萬(wàn)虹點(diǎn)讀機(jī)如何做系統(tǒng)下載網(wǎng)站公司seo推廣營(yíng)銷網(wǎng)站
  • 全屋定制加盟品牌加盟網(wǎng)杭州做seo的公司
  • magento 網(wǎng)站seo優(yōu)化與推廣招聘
  • 聊城做網(wǎng)站的公司咨詢最常用的幾個(gè)關(guān)鍵詞
  • 網(wǎng)站建設(shè)主管招聘浙江百度查關(guān)鍵詞排名
  • seo優(yōu)化銷售seo網(wǎng)上培訓(xùn)課程
  • 邯鄲專業(yè)做網(wǎng)站報(bào)價(jià)建設(shè)網(wǎng)站公司
  • 1核2g 做網(wǎng)站百度手機(jī)應(yīng)用商店
  • 做網(wǎng)站的小圖標(biāo)360網(wǎng)站排名優(yōu)化
  • 昆明哪些做網(wǎng)站建設(shè)的公司網(wǎng)站惡意點(diǎn)擊軟件
  • 做水果網(wǎng)站行營(yíng)銷推廣的形式包括
  • 亞馬遜網(wǎng)站推廣怎么做學(xué)網(wǎng)絡(luò)營(yíng)銷有用嗎
  • 浙江做網(wǎng)站的公司百度公司招聘信息
  • 哪個(gè)網(wǎng)站做調(diào)查問(wèn)卷賺錢長(zhǎng)春seo招聘
  • 騰訊云注冊(cè)域名后怎么做網(wǎng)站剛剛突發(fā)1驚天大事
  • wex5網(wǎng)站開發(fā)北京seo助理
  • 南京電商網(wǎng)站建設(shè)公司百度搜索引擎的原理
  • 免費(fèi)茶葉網(wǎng)站建設(shè)點(diǎn)擊器
  • 360免費(fèi)做網(wǎng)站電腦零基礎(chǔ)培訓(xùn)班
  • icp備案 網(wǎng)站服務(wù)內(nèi)容蘇州網(wǎng)站制作開發(fā)公司
  • 上海網(wǎng)站建設(shè)方案托管銀川seo
  • 太原網(wǎng)站設(shè)計(jì)公司軟件開發(fā)定制
  • 鄭州網(wǎng)站建設(shè)國(guó)奧大廈網(wǎng)站seo資訊
  • 時(shí)時(shí)彩網(wǎng)站開發(fā)違法嗎升華網(wǎng)絡(luò)推廣軟件
  • 濮陽(yáng)市建設(shè)分局網(wǎng)站百度賬號(hào)中心
  • qq郵箱登錄入口網(wǎng)頁(yè)版廣州seo網(wǎng)站推廣公司
  • 搭建cms網(wǎng)站網(wǎng)絡(luò)互聯(lián)網(wǎng)推廣
  • 廣東兩學(xué)一做網(wǎng)站西安網(wǎng)是科技發(fā)展有限公司
  • 江門模板建站哪家好網(wǎng)站推廣網(wǎng)絡(luò)營(yíng)銷方案
  • 網(wǎng)站里的橫幅怎么做項(xiàng)目網(wǎng)站