#include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(){ int n, k, x; vector<int> v1, v2; scanf("%d%d", &n, &k); for(int i=0; i<n; i++){ scanf("%d", &x); v1.push_back(x); } for(int i=0; i<n; i++){ scanf("%d", &x); v2.push_back(x); } int c = 0; long long total1 = 0, total2 = 0; for(int i=0; i<n; i++){ int half = (v1[i] + v2[i]) / 2; int diff1 = abs(v1[i] - half); int diff2 = abs(v2[i] - half); if(diff1 != diff2){ if(c % 2 == 1) half = (v1[i] > v2[i] ? (v1[i] + 1 + v2[i]) / 2 : (v1[i] - 1 + v2[i]) / 2); else half = (v1[i] > v2[i] ? (v1[i] + v2[i] - 1) / 2 : (v1[i] + v2[i] + 1) / 2); ++c; } total1 += abs(half - v1[i]); total2 += abs(half - v2[i]); printf("%d ", half); } //printf("%lld\n", max(total1, total2)); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(){ int n, k, x; vector<int> v1, v2; scanf("%d%d", &n, &k); for(int i=0; i<n; i++){ scanf("%d", &x); v1.push_back(x); } for(int i=0; i<n; i++){ scanf("%d", &x); v2.push_back(x); } int c = 0; long long total1 = 0, total2 = 0; for(int i=0; i<n; i++){ int half = (v1[i] + v2[i]) / 2; int diff1 = abs(v1[i] - half); int diff2 = abs(v2[i] - half); if(diff1 != diff2){ if(c % 2 == 1) half = (v1[i] > v2[i] ? (v1[i] + 1 + v2[i]) / 2 : (v1[i] - 1 + v2[i]) / 2); else half = (v1[i] > v2[i] ? (v1[i] + v2[i] - 1) / 2 : (v1[i] + v2[i] + 1) / 2); ++c; } total1 += abs(half - v1[i]); total2 += abs(half - v2[i]); printf("%d ", half); } //printf("%lld\n", max(total1, total2)); return 0; } |