-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
82 lines (74 loc) · 1.29 KB
/
test.cpp
File metadata and controls
82 lines (74 loc) · 1.29 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
using namespace std;
class A
{
public:
A(int l) : l(l)
{
}
A(int v, int l) : val(v), l(l)
{
}
int val;
int l;
};
bool cmp(A a, A b)
{
if (a.val == b.val)
{
return a.l < b.l;
}
return a.val > b.val;
}
int main()
{
int len;
cin >> len;
vector<A> arr;
string lens, vs;
cin >> lens;
cin >> vs;
int s = 0;
for (int i = 0; i < lens.size(); ++i)
{
if (lens[i] == ',')
{
arr.push_back(A(atoi(lens.substr(s, i).c_str())));
s = i+1;
}
}
arr.push_back(A(atoi(lens.substr(s).c_str())));
s = 0;
int t = 0;
for (int i = 0; i < vs.size(); ++i)
{
if (vs[i] == ',')
{
arr[t++].val = atoi(vs.substr(s).c_str());
s = i+1;
}
}
arr[t++].val = atoi(vs.substr(s).c_str());
int res = 0;
sort(arr.begin(), arr.end(), cmp);
int cur = len;
for (int i = 0; i < arr.size(); ++i)
{
if (arr[i].l <= cur)
{
cur -= arr[i].l;
res += arr[i].val;
}
else
{
break;
}
}
cout << res << endl;
return 0;
}