Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n, p1, p2, p3, g1, g2, g3;
- cin >> n;
- vector<pair<int, int> >v(3);
- cin >> v[0].first >> v[1].first >> v[2].first;
- cin >> v[0].second >> v[1].second >> v[2].second;
- sort(v.begin(), v.end());
- int ans = INT_MAX;
- g1 = v[0].first, g2 = v[1].first, g3 = v[2].first;
- p1 = v[0].second, p2 = v[1].second, p3 = v[2].second;
- for(int i = 1; i+p1-1+p2+p3 <= n; i++ ){
- for(int j = i+p1; j+p2-1+p3 <= n; j++){
- for(int k = j+p2; k+p3-1 <= n; k++){
- int tmp = 0;
- for(int t = i; t < i+p1; t++){
- tmp += abs(g1 - t) + 1;
- }
- for(int t = j; t < j+p2; t++){
- tmp += abs(g2 - t) + 1;
- }
- for(int t = k; t < k+p3; t++){
- tmp += abs(g3 - t) + 1;
- }
- ans = min (ans, tmp);
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement