Given an array of integers A and an integer k,
find a subarray that contains the largest sum,
subject to a constraint that the sum is less than k?
vector<int> vec = {3,4,1,2,4,1,-5};
int k = 0;
int main() {
set<int> seq;
int sum = 0;
int res = INT_MIN;
for (auto e : vec) {
sum += e;
auto iter = seq.lower_bound(sum - k);
if (iter != seq.end()) {
res = max(res, sum - *iter);
}
seq.emplace(sum);
}
cout << res << endl;
return 0;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。