-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcc_KCOMPRESS..cpp
More file actions
75 lines (65 loc) · 1.4 KB
/
Copy pathcc_KCOMPRESS..cpp
File metadata and controls
75 lines (65 loc) · 1.4 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Author : Abhinav
Modified : 10-08-2018 11:06:39 PM
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define faster ios_base::sync_with_stdio(false);cin.tie(0);
const ll mod = 1e9+7;
#define rep(i,j,k) for(ll i=j; i<k; i++)
#define repv(i,j,k) for(ll i=j; i>k; i--)
ll kcompress(vi a, vi b,ll k,ll n){
ll lw,hh,mx,ff=1;
rep(i,1,n+1){
lw = max(ff,i-k);
hh = min(n,i+k);
cout << "Low = " << lw << " High = " << hh << "\n";
vi tp(a);
sort(tp.begin()+lw,tp.begin()+hh+1);
map<ll,ll> m;
ll ctr=1;
/*for(auto itr=tp.begin(); itr!=tp.end(); itr++)
cout << *itr << " ";
cout << "\n";*/
for(auto itr=tp.begin()+lw; itr!=tp.begin()+hh+1; itr++){
//if(!m[*itr]){
m[*itr] = ctr;
ctr++;
//}
//cout << m[*itr] << "\n";
}
/*for(auto it=m.begin(); it!=m.end(); it++)
cout << it->first << " " << it->second << "\n";*/
for(int j=lw; j<=hh; j++){
b[j] = m[a[j]];
}
}
cout << "K = " << k << "\n";
rep(i,0,n+1)
cout << b[i] << " ";
cout << "\n";
cout << accumulate(b.begin(), b.end(), 0) << "\n";
return accumulate(b.begin(), b.end(), 0);
}
int main(){
faster;
ll t,n,s,sum,ctr;
cin >> t;
while(t--){
cin >> n >> s;
vi a(n+1);
rep(i,1,n+1)
cin >> a[i];
ctr=0;
for(int k=0; k<=n; k++){
vi b(n+1,0);
b[0] = 0;
sum = kcompress(a,b,k,n);
if(sum<=s) ctr++;
}
cout << ctr << "\n";
}
return 0;
}