Advertisement
mickypinata

TOI10: Crazy Admin

May 3rd, 2020
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. #define lli long long
  6.  
  7. vector<int> rooms;
  8. int nw, nr;
  9.  
  10. int main(){
  11.  
  12.     int x;
  13.  
  14.     scanf("%d %d", &nw, &nr);
  15.     rooms.assign(nr + 1, 0);
  16.     for(int i = 1; i <= nr; ++i){
  17.         scanf("%d", &x);
  18.         rooms[i] = x;
  19.     }
  20.  
  21.     int l = 1;
  22.     int r = 150000;
  23.     int ans = 150000;
  24.     while(l <= r){
  25.         int m = (l + r) / 2;
  26.         int cnt = 1;
  27.         int sum = 0;
  28.         int mx = 0;
  29.         for(int i = 1; i <= nr; ++i){
  30.             if(sum + rooms[i] <= m){
  31.                 sum += rooms[i];
  32.             } else {
  33.                 mx = max(mx, sum);
  34.                 sum = rooms[i];
  35.                 ++cnt;
  36.             }
  37.         }
  38.         mx = max(mx, sum);
  39.         if(cnt > nw){
  40.             l = m + 1;
  41.         } else {
  42.             ans = min(ans, mx);
  43.             r = m - 1;
  44.         }
  45.     }
  46.  
  47.     cout << ans;
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement