【NOIP2018普及组】龙虎斗

【NOIP2018普及组】龙虎斗

【NOIP2018普及组】龙虎斗_第1张图片
【NOIP2018普及组】龙虎斗_第2张图片
题解
二分答案就可以了

#include
#define ll long long
using namespace std;
int n,m,p1;
ll s1,s2;
ll num[100050],ans;
int flag;
ll sc;
ll sljc;
ll read(){
   ll number=0;
   char ch=getchar();
   while(ch>'9'||ch<'0'){
   	ch=getchar();
   }
   while(ch>='0'&&ch<='9'){
   	number=(number<<1)+(number<<3)+ch-'0';
   	ch=getchar();
   }
   return number;
}
int main(){
   n=read();
   for(int i=1;i<=n;i++){
   	num[i]=read();
   }
   m=read(),p1=read(),s1=read(),s2=read();
   num[p1]+=s1;
   flag=1;
   for(int i=1;i<=n;i++){
   	num[i]*=(i-m);
   	ans+=num[i];
   }
   int l=1,r=n;
   while(l<=r){
   	int mid=(l+r)>>1;
   	if(((mid-1>=1&&mid+1<=n)&&abs(s2*(mid-m)+ans)n){
   			printf("%d",mid);
   			return 0;
   		}
   		if(abs(s2*(mid-m)+ans)n){
   		if(abs(s2*(mid-m)+ans)

你可能感兴趣的:(普及组)