Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Triplet sum in array
#include<bits/stdc++.h> using namespace std; int dos(vector<int>&v,int l,int r,int rem_sum) { while(l<r) { if(v[l]+v[r]==rem_sum) { return 1; } else if(v[l]+v[r]>rem_sum) { r--; } else { l++; } } return 0; } int tos(vector<int>&v,int n,int target) { for(int i=n-1;i>=2;i--) { if(dos(v,0,i-1,target-v[i])) return 1; } return 0; } int main() { int t; cin>>t; while(t--) { int n;int target; cin>>n; cin>>target; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; sort(v.begin(),v.end()); cout<<tos(v,n,target)<<endl; } }
run
|
edit
|
history
|
help
0
Hello World
Count edges in a graph
Boost phoenix. e.g 2: functor
cache 内存消耗
Dar
gcc set_terminate
მატრიცა#2
Building squares using smallest amount of matches
VirtualRestoPoint
DP Optimization another kind