-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepositosN1
59 lines (48 loc) · 1.06 KB
/
DepositosN1
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//Timing: 32:37
#include <bits/stdc++.h>
using namespace std;
struct cmp{
operator()(pair<int,int> a, pair<int,int> b){
return a.second > b.second;
}
};
int n,v,a,b,maxv=0;
vector< pair<int,int> > lista;
pair<int,int> ct(int a){
int i, temp=0;
for(i=0;i<lista.size();i++){
if(lista[i].second > 0){
if(lista[i].second < a)
break;
lista[i].second--;
temp+=lista[i].first;
}
}
return make_pair(i,temp);
}
int main(){
ifstream fin("in.txt");
fin >> n;
for(int i=1;i<=n;i++){
fin >> a >> b;
lista.push_back(make_pair(a,b));
}
fin >> v;
sort(lista.begin(), lista.end(), cmp());
maxv = lista[0].second;
pair<int,int> temp;
int i;
for(i=maxv;i>0;i--){
if(v <= 0)
break;
temp = ct(i);
if(temp.second != 0)
v-= temp.second;
else
break;
}
if(v > 0)
cout << "Rebasan: " << v << endl;
else
cout << temp.first << endl << i << endl;
}