#include <bits/stdc++.h>
#include "molecules.h"
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("cowrect.in","r",stdin)
#define OUTP freopen ("cowrect.out","w",stdout)
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<int,int> > start;
for(int i(0); i < w.size();i++){
start.push_back({w[i],i});
}
sort(start.begin(),start.end());
sort(w.begin(),w.end());
if(w[0] > u)return {};
long long res = 0;
for(int i(0); i < w.size();i++){
res+=w[i];
}
if(res < l)return {};
if(res>=l && res<=u){
return w;
}
res = 0;
set<pair<int,int> > s;
int cnt = 0;
int pnt = 0;
for(int i(0); i < w.size();i++){
if(res + w[i] > u)break;
res+=w[i];
cnt++;
s.insert({w[i],i});
pnt++;
}
//cout << res << ' ' << cnt << endl;
vector<int> v;
while(cnt){
int now = s.begin()->first;
res-=now;
res+=w[pnt];
s.erase(s.begin());
s.insert({w[pnt],pnt});
pnt++;
cnt--;
//cout << res << ' ' << l << ' ' << u << endl;
if(res>=l && res <=u){
int pnt = 0;
for(auto& a: s)v.push_back(start[a.second].second);
break;
}
if(pnt == w.size())break;
}
//cout << res << endl;
return v;
}
/*
main(){
ios_base::sync_with_stdio(0);
int l,u,n; cin >> l >> u >> n;
vector<int> v;
for(int i(0); i < n;i++){
int x; cin >> x;
v.push_back(x);
}
vector<int> ans = find_subset(l,u,v);
for(int i(0); i < ans.size();i++)cout << ans[i] << ' ';
return 0;
}
*/
/*
15 17 4
6 8 8 7
14 15 4
5 5 6 6
10 20 4
15 17 16 18
16 29 5
10 10 10 10 10
*/
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i(0); i < w.size();i++){
~~^~~~~~~~~~
molecules.cpp:20:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i(0); i < w.size();i++){
~~^~~~~~~~~~
molecules.cpp:31:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i(0); i < w.size();i++){
~~^~~~~~~~~~
molecules.cpp:50:17: warning: unused variable 'pnt' [-Wunused-variable]
int pnt = 0;
^~~
molecules.cpp:54:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pnt == w.size())break;
~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
3 ms |
376 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
2 ms |
256 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
3 ms |
256 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
2 ms |
256 KB |
OK (n = 12, answer = NO) |
5 |
Incorrect |
2 ms |
256 KB |
Contestant can not find answer, jury can |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
3 ms |
376 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
3 ms |
376 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
3 ms |
376 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
3 ms |
376 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |