#include "molecules.h"
#include <algorithm>
#include <cstdio>
using namespace std;
struct Seq{
int val,id;
}seq[200005];
bool comp(Seq x,Seq y)
{
return x.val<y.val;
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
for(int i=0;i<w.size();i++)
{
seq[i].val=w[i];
seq[i].id=i;
}
sort(seq,seq+w.size(),comp);
int left=0,right=0;
int sum=seq[0].val;
while(left<=right)
{
//printf("%d %d %d %d %d\n",left,right,sum,l,u);
if(sum<l && right<w.size())
{
right++;
sum+=seq[right].val;
}
if(sum>u && left<=right)
{
sum-=seq[left].val;
left++;
}
//printf("%d %d %d %d %d\n",left,right,sum,l,u);
if(l<=sum && sum<=u)break;
}
if(!(l<=sum && sum<=u))
return vector<int> (0);
vector<int> ans;
for(int i=left;i<=right;i++)
{
ans.push_back(seq[i].id);
}
return ans;
}
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w.size();i++)
~^~~~~~~~~
molecules.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(sum<l && right<w.size())
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
2 ms |
256 KB |
OK (n = 12, answer = YES) |
3 |
Execution timed out |
1070 ms |
252 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |