QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246926 | #5137. Tower | sfjh | WA | 67ms | 3824kb | C++14 | 834b | 2023-11-11 12:37:02 | 2023-11-11 12:37:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define fdr(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define endl '\n'
const int N=510;
const int INF=1e18+10;
int n,m;
int a[N];
int get(int x,int y){
if(x<=y) return y-x;
int res=abs(y-x);
while(x>y){
x/=2;
res=min(abs(x-y)+1,res);
}
return res;
}
void solve(){
cin>>n>>m;
fer(i,1,n) cin>>a[i];
int ans=INF;
fer(i,1,n){
int x=a[i];
while(x){
vector<int> v;
int sum=0;
fer(j,1,n) v.pb(get(a[j],x));
sort(v.begin(),v.end());
for(int j=0;j<n-m;j++) sum+=v[j];
ans=min(ans,sum);
x/=2;
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 67ms
memory: 3824kb
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:
151 3 144 43 197 179 278 78 179 29
result:
wrong answer 1st numbers differ - expected: '454', found: '151'