QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#521774 | #5137. Tower | potential | WA | 5ms | 3580kb | C++20 | 1.5kb | 2024-08-16 14:41:51 | 2024-08-16 14:41:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define int long long
#define lowbit(x) (x&(-x))
#define pll pair<int,int>
const int N = 1e6 +10;
const int mod = 1e9+7;
const double eps = 1e-6;
int dx[] = {-1,1,0,0,-1,-1,1,1};
int dy[] = {0,0,-1,1,-1,1,-1,1};
int n,m,k;
int a[N];
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
auto check = [&](int x) -> int{
priority_queue<int> q;
int res = 0;
for(int i=1;i<=n;i++){
int ned = 1e18;
if(a[i]==x) ned = 0;
else if(a[i]<x) ned = x-a[i];
else{
int t = a[i];
int cnt = 0;
while(t){
ned = min(ned,cnt+abs(t-x));
t /= 2;
cnt++;
}
ned = min(ned,cnt+abs(t-x));
}
res += ned;
q.push(ned);
}
int c = m;
while(q.size()&&m-->0){
res -= q.top();
q.pop();
}
return res;
};
int ans = 1e18;
for(int i=1;i<=n;i++){
ans = min(ans,check(a[i]));
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int T = 1;
cin>>T;
while(T--){
solve();
}
return 0;
}
/*
3
2 0
2 6
5 0
1 2 3 4 5
5 3
1 2 3 4 5
/\_/\
(= ._.)
/ > \>
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
3 2 0 2 6 5 0 1 2 3 4 5 5 3 1 2 3 4 5
output:
2 4 1
result:
ok 3 number(s): "2 4 1"
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3544kb
input:
10 272 118 11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...
output:
623 14 543 166 811 716 1219 260 816 102
result:
wrong answer 1st numbers differ - expected: '454', found: '623'