/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 344.0 KiB
#3 Accepted 26ms 568.0 KiB
#4 Accepted 48ms 792.0 KiB
#5 Accepted 189ms 564.0 KiB
#6 Accepted 76ms 576.0 KiB
#7 Accepted 149ms 2.832 MiB
#8 Accepted 144ms 640.0 KiB
#9 Accepted 95ms 1.309 MiB
#10 Accepted 89ms 576.0 KiB
#11 Accepted 315ms 784.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
void solve()
{
   ll n  , s  ; cin >> n >> s; ll a[n] ;
   for(int i = 0 ; i < n ; i++) cin >> a[i];
   ll Ans = INT_MAX , Low = 1 , High = 1e12;
   bool ok = 1 ;
   while(Low <= High){
    ll X = (Low + High) >> 1 ;
    ll curSum = 0 ;
    for(auto it : a) curSum += (it / X) ;
    if(curSum == s){
        ok = 0 ;
        Ans = min(Ans , X) ;
    }
    if(curSum > s) Low = X + 1 ;
    else High = X - 1 ;
   // cout << Low << " " << High << " " << X << " " << curSum << endl ;
   }
   if(ok) cout << -1 << "\n" ;
   else cout << Ans << "\n" ;


}
int main()
{
     __Heart__
   // READ("0in.txt") ;
    // WRITE("0out.txt") ;
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1057 Floor Sum
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-16 16:31:46
Judged At
2024-11-11 02:36:40
Judged By
Score
100
Total Time
315ms
Peak Memory
2.832 MiB