谨以此篇记录我的一个思维缺陷
Problem Statement
Takahashi had N glasses of liquor.The amount and alcohol percentage of the i-th liquor were Vi milliliters and Pi percent by volume, respectively.
Takahashi gets drunk when his alcohol intake exceeds X milliliters.
Which of the N liquors was he drinking when he gets drunk? If he was not drunk even after drinking allthe liquors, print -1 instead.
Constraints
All values in input are integers.
1≤N≤10^3
0≤X≤10^6
1≤Vi≤10^3
0≤Pi≤100
Input
Input is given from Standard Input in the following format:
Output
If Takahashi got drunk when drinking the i-th liquor, print i. If he was not drunk even after drinking all the liquors, print -1 instead.
Sample Input 1
2 15
200 5
350 3
Sample Output 1
2
Sample Input 2
2 10
200 5
350 3
Sample Output 2
2
Sample Input 3
3 1000000
1000 100
1000 100
1000 100
Sample Output 3
-1
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
int sum=0;
cin>>n>>x;
x*=100;//此篇意义所在之处
int v[1005];
for(int i=0;i<n;i++){
int z,y;
cin>>z>>y;
v[i]=z*y;
}
for(int k=0;k<n;k++){
sum+=v[k];
if(sum>x) {
cout<<k+1;
return 0;
}
}
cout<<"-1";
return 0;
}
总结
此题思路很简单,而记录此篇的意义在于,我一个逆向思维的缺乏。