Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //boat competition
- #include<bits/stdc++.h>
- using namespace std;
- // int main()
- // {
- // int t;
- // cin >> t;
- // while (t--)
- // {
- // int n, i, j, ans = 0, count = 0, k;
- // cin >> n;
- // int a[n];
- // for (i = 0; i < n; i++)
- // {
- // cin >> a[i];
- // }
- // sort(a, a + n);
- // //two pointers ->on sorted array
- // for (k = 2; k <= 100; k++)
- // {
- // count = 0;
- // i = 0; j = n - 1;
- // while (i < j)
- // {
- // if (a[i] + a[j] == k)
- // {
- // i++; j--;
- // count++;
- // }
- // else if (a[i] + a[j] > k)
- // {
- // j--;
- // }
- // else
- // {
- // i++;
- // }
- // }
- // if (count > ans)
- // {
- // ans = count;
- // }
- // }
- // cout << ans << " " << endl;
- // }
- // return 0;
- // }
- /////problem->heaters
- // class Solution {
- // public:
- // bool can(vector<int>& houses,int radius,vector<int>& heaters)
- // {
- // int n=houses.size();
- // int m=heaters.size();
- // int l=0,r=0;
- // while(l<n&&r<m)
- // {
- // if(abs(houses[l]-heaters[r])<=radius)
- // {
- // l++;
- // }
- // else
- // {
- // r++;
- // }
- // }
- // if(l==n) return true;//all houses can be covered
- // return false;
- // }
- // int findRadius(vector<int>& houses, vector<int>& heaters)
- // {
- // sort(houses.begin(), houses.end());
- // sort(heaters.begin(), heaters.end());
- // int low=0,high=(int)1e9+1,ans;
- // while(low<=high)
- // {
- // int curr_radius=(low+(high-low)/2);
- // if(can(houses,curr_radius,heaters))
- // {
- // //all houses can be covered
- // ans=curr_radius;
- // high=curr_radius-1;
- // }
- // else
- // {
- // low=curr_radius+1;
- // }
- // }
- // //min curr radius by which all houses should be covered
- // return ans;
- // }
- // };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement