#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k;
cin >> n >> k;
vector<ll> price(n), sell(n);
FOR(i,0,n) cin >> price[i];
FOR(i,0,n) cin >> sell[i];
ll ans = -1000000000000000;
FOR(i,0,n){
set<array<ll,2>> stuff;
ll sum = 0;
ll cost = 0;
FOR(j,i,n){
cost += price[j];
sum += sell[j];
stuff.insert({sell[j], j});
if (stuff.size() > k){
auto it = stuff.begin();
sum -= (*it)[0];
stuff.erase(it);
}
if (stuff.size()==k) ans = max(ans, sum-cost);
}
}
cout << ans << "\n";
vector<ll> used(n);
FOR(i,0,n){
set<array<ll,2>> stuff;
ll sum = 0;
ll cost = 0;
FOR(j,i,n){
cost += price[j];
sum += sell[j];
stuff.insert({sell[j], -j});
if (stuff.size() > k){
auto it = stuff.begin();
sum -= (*it)[0];
stuff.erase(it);
}
if (stuff.size()==k && (sum-cost) == ans){
for (auto&i : stuff) used[-i[1]] = 1;
}
}
}
for (auto&i : used) cout << i;
}
Compilation message
trade.cpp: In function 'int main()':
trade.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::set<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
30 | if (stuff.size() > k){
| ~~~~~~~~~~~~~^~~
trade.cpp:36:20: warning: comparison of integer expressions of different signedness: 'std::set<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
36 | if (stuff.size()==k) ans = max(ans, sum-cost);
| ~~~~~~~~~~~~^~~
trade.cpp:56:21: warning: comparison of integer expressions of different signedness: 'std::set<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
56 | if (stuff.size() > k){
| ~~~~~~~~~~~~~^~~
trade.cpp:62:20: warning: comparison of integer expressions of different signedness: 'std::set<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
62 | if (stuff.size()==k && (sum-cost) == ans){
| ~~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Partially correct |
3 ms |
348 KB |
Partially correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Partially correct |
5 ms |
348 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Partially correct |
3 ms |
348 KB |
Partially correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Partially correct |
5 ms |
348 KB |
Partially correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Partially correct |
3 ms |
348 KB |
Partially correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Partially correct |
3 ms |
460 KB |
Partially correct |
23 |
Correct |
4266 ms |
996 KB |
Output is correct |
24 |
Correct |
1020 ms |
604 KB |
Output is correct |
25 |
Partially correct |
3213 ms |
600 KB |
Partially correct |
26 |
Partially correct |
2190 ms |
604 KB |
Partially correct |
27 |
Execution timed out |
8039 ms |
600 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
8061 ms |
5212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
8061 ms |
5212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Partially correct |
3 ms |
348 KB |
Partially correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Partially correct |
5 ms |
348 KB |
Partially correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
4 ms |
344 KB |
Output is correct |
22 |
Partially correct |
3 ms |
348 KB |
Partially correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Partially correct |
3 ms |
460 KB |
Partially correct |
25 |
Correct |
4266 ms |
996 KB |
Output is correct |
26 |
Correct |
1020 ms |
604 KB |
Output is correct |
27 |
Partially correct |
3213 ms |
600 KB |
Partially correct |
28 |
Partially correct |
2190 ms |
604 KB |
Partially correct |
29 |
Execution timed out |
8039 ms |
600 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |