How do T avoid truncated integer division in this code? My sorted array is 1 1 1 1 1 1
, so a[0] = 1 and a[n] should be 1 / 2 = 0.5.
int main()
{
long long n,w;
scanf("%lld %lld", &n, &w);
long long arr[2*n];
for(long long i = 0; i < 2 * n; i++)
{
scanf("%lld", &arr[i]);
}
sort(arr,arr+2*n);
long long a = arr[0];
long long b = (float)(arr[n]/2); // <--- this part of code
cout << " a is " << a << endl;
cout << " b is " << b << endl;
long long m = min(a,b);
cout << " m is " << m << endl;
long long and = min(m * n + m * 2LL * n, w);
printf("%lld", ans);
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…