Advertisement
Mohammad_Dipu_Sultan

FisherMan SRBD

Oct 13th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.    
  6.     int n, p1, p2, p3, g1, g2, g3;
  7.     cin >> n;
  8.     vector<pair<int, int> >v(3);
  9.  
  10.     cin >> v[0].first >> v[1].first >> v[2].first;
  11.     cin >> v[0].second >> v[1].second >> v[2].second;
  12.     sort(v.begin(), v.end());
  13.     int ans = INT_MAX;
  14.     g1 = v[0].first, g2 = v[1].first, g3 = v[2].first;
  15.     p1 = v[0].second, p2 = v[1].second, p3 = v[2].second;
  16.  
  17.     for(int i = 1; i+p1-1+p2+p3 <= n; i++ ){
  18.         for(int j = i+p1; j+p2-1+p3 <= n; j++){
  19.             for(int k = j+p2; k+p3-1 <= n; k++){
  20.                 int tmp = 0;
  21.                 for(int t = i; t < i+p1; t++){
  22.                     tmp += abs(g1 - t) + 1;
  23.                 }
  24.                 for(int t = j; t < j+p2; t++){
  25.                     tmp += abs(g2 - t) + 1;
  26.                 }
  27.                 for(int t = k; t < k+p3; t++){
  28.                     tmp += abs(g3 - t) + 1;
  29.                 }
  30.                 ans = min (ans, tmp);
  31.             }
  32.         }
  33.     }
  34.     cout << ans << endl;
  35.     return 0;
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement