来源:

思路:s累加量乘浓度,然后到s>x*100时输出i,没醉输出-1,如果用累加量乘浓度/100.0和x比会出精度错误。
代码

#include<bits/stdc++.h>
using namespace std;
long long n,x,v,p,s,i;
int main(){
    
    
	scanf("%lld%lld",&n,&x);
	for(i=1;i<=n;i++){
    
    
		scanf("%lld%lld",&v,&p);
		s+=v*p;
		if(s>x*100){
    
    
			printf("%lld",i);
			return 0;
		}
	}
	printf("-1");
}

猜你喜欢

转载自blog.csdn.net/weixin_52536621/article/details/113093827