MYF

PKU Campus A Investing Your Prize

题目链接

C16A:Investing Your Prize
水题

题目分析

题目大意

某人想去买理财产品,给出这个人手里的钱数p,以及n种理财产品,每种理财产品有不同的l, r,分别代表该产品的起购金额和年利率,问,这个人选哪种方案赚的钱最多?

解析

每次输入的时候判断,如果手里的钱大于等于起购金额,且当前的理财方案比之前选的年利率更高的话,就选新的。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <deque>
#include <algorithm>
#define Memset(a,val) memset(a,val,sizeof(a))
#define PI acos(-1)
#define rt(n) (i == n ? '\n' : ' ')
#define hi printf("Hi----------\n")
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("output.txt","w",stdout);
#define debug(x) cout<<"Debug : ---"<<x<<"---"<<endl;
#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long ll;
using namespace std;
const int maxn=100000+5;
const int mod=1000000007;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
double l[maxn],r[maxn];
int main(){
int t;
int n;
double p;
scanf("%d",&t);
while (t--) {
int ans=0;
cin>>n>>p;
for (int i=1; i<=n; i++) {
cin>>l[i]>>r[i];
if (l[i]<=p&&r[i]>=r[ans]) {
ans=i;
}
}
cout<<ans<<endl;
}
}