Untitled
raw download clone
CPP
views 8
,
size 1542 b
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

using namespace std;

struct days{
    const vector<int> &coffee;
    int HowManyDays;

    days(const vector<int> &_coffee, int _HowManyDays):coffee{_coffee}, HowManyDays{_HowManyDays} {}

    long long calculateCodeLine()const{
        int decrease = 0;
        int dayCounter = 0;
        long long codeLines = 0;
        for(int i:coffee){
            if(i < decrease){
                break;
            }
            codeLines += (i-decrease);
            ++dayCounter;
            if(dayCounter == HowManyDays){
                ++decrease;
                dayCounter = 0;
            }
        }
        return codeLines;
    }

    bool operator < (const long long &rhs)const{
        return (calculateCodeLine() < rhs);
    }
};


int main()
{
    int t, n;
    long long m;
    cin>>t;
    while(t--){
        cin>>n>>m;
        vector<int> coffee(n);
        for(int i = 0; i < n; i++){
            int temp;
            cin>>temp;
            coffee[i] = temp;
        }
        vector<days> dayVec;
        dayVec.reserve(n);
        for(int i = 1; i <= n; i++){
            dayVec.push_back(days(coffee, i));
        }
        vector<days>::iterator output = lower_bound(dayVec.begin(), dayVec.end(), m);
        if(output != dayVec.end()){
            cout<<output->HowManyDays<<"\n";
        }
        else{
            cout<<"-1\n";
        }
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.