-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncandiesKpeople.cpp
102 lines (102 loc) · 2.18 KB
/
ncandiesKpeople.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <cmath>
#include <stack>
#include <cstring>
#include <stdlib.h>
#include <unordered_set>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#define vi vector<int>
#define vvi vector<vi>
#define pii vector<int, int>
#define vii vector<pii>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define ss second
using namespace std;
vector<int> solve(int n,int k){
int count=0;
int ind=1;
vector<int>ans(k,0);
while(n){
int t1=(ind-1)*k;
int t2=(ind)*k;
int s1=(t1*(t1+1))/2;
int s2=(t2*(t2+1))/2;
int res=s2-s1;
if(res<=n){
count++;
n-=res;
ind++;
}
else{
int i=0;
int term=((ind-1)*k)+1;
while(n>0){
if(term<=n){
ans[i++]=term;
n-=term;
term++;
}
else{
ans[i++]=n;
n=0;
}
}
}
}
for(int i=0;i<k;i++){
ans[i]+=(count*(i+1))+(k*count*(count-1))/2;
}
return ans;
}
vector<int> solvebs(int n,int k){
int count=0;
int ind=1;
vector<int>ans (k,0);
int low=0,high=n;
while(low<=high){
int mid=(low+high)/2;
int sum=(mid*(mid+1))/2;
if(sum<=n){
count=mid/k;
low=mid+1;
}
else high=mid-1;
}
int last=(count*k);
n-=(last*(last+1))/2;
int i=0;
int term=(count*k)+1;
while(n){
if(term<=n){
ans[i++]=term;
n-=term;
term++;
}
else {
ans[i]+=n;
n=0;
}
}
for(int i=0;i<k;i++){
ans[i]+=(count*(i+1))+(k*(count-1)/2);
}
}
vector<int> dist(int n,int k){
vector<int> res(k,0);
int i=0;
while(n>0){
int to_distri=min(n,i+1);
res[i%k]+=to_distri;
n-=to_distri;
i+=1;
}
return res;
}