-
Notifications
You must be signed in to change notification settings - Fork 0
/
812C.cpp
50 lines (43 loc) · 812 Bytes
/
812C.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll find(ll t , ll a[] , ll n)
{
vector <ll > temp;
for(int i = 0; i < n ; i ++)
{
temp.push_back(a[i] + (i + 1) * t);
}
sort(temp.begin() , temp.end());
ll total = 0;
for(int i = 0; i< t; i ++)
total += temp[i];
return total;
}
int main()
{
ll n , m;
cin >> n >> m;
ll a[n];
for(int i =0 ; i < n ; i++)
cin >> a[i];
ll l = 1;
ll r = n;
ll ans = 0;
ll c = 0;
while( l<= r)
{
ll mid = l + (r - l)/2;
ll cost = find(mid , a , n);
if(cost <= m)
{
ans = mid;
c = cost;
l = mid + 1;
}
else
r = mid - 1;
}
cout << ans << " " << c << endl;
}