2 条题解

  • 1
    @ 2024-12-23 17:16:55
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int arr[100005];
    double sum[100005];
    int n, F;
    
    bool fun(double aver) {
        for(int i = 1; i <= n; i++) {
            sum[i] = sum[i - 1] + arr[i] - aver;    
        }
        double minn = 1e9, ans = -1e9;
        for(int i = F; i <= n; i++) {
            minn = min(minn, sum[i - F]);       
            ans = max(ans, sum[i] - minn);
        }
        return ans >= 0;
    }
    
    int main() {
        scanf("%d %d", &n, &F);
        for(int i = 1; i <= n; i++) {
            scanf("%d", &arr[i]);
        }
        double l = -1e6, r = 1e6;
        while(r - l > 1e-5) {
            double mid = (l + r) / 2.0;
            if(fun(mid)) {
                l = mid;
            } else {
                r = mid;
            }
        }
        cout << (long long)(r * 1000) << endl;
        return 0;
    }
    
    
    • -1
      @ 2024-3-31 15:33:56
      #include <iostream>
      #include <cstdio>
      
      using namespace std;
      
      int arr[100005];
      double sum[100005];
      int n, F;
      
      bool fun(double aver) {
          for(int i = 1; i <= n; i++) {
              sum[i] = sum[i - 1] + arr[i] - aver;    
          }
          double minn = 1e9, ans = -1e9;
          for(int i = F; i <= n; i++) {
              minn = min(minn, sum[i - F]);       
              ans = max(ans, sum[i] - minn);
          }
          return ans >= 0;
      }
      
      int main() {
          scanf("%d %d", &n, &F);
          for(int i = 1; i <= n; i++) {
              scanf("%d", &arr[i]);
          }
          double l = -1e6, r = 1e6;
          while(r - l > 1e-5) {
              double mid = (l + r) / 2.0;
              if(fun(mid)) {
                  l = mid;
              } else {
                  r = mid;
              }
          }
          cout << (long long)(r * 1000) << endl;
          return 0;
      }
      
      • 1

      信息

      ID
      14
      时间
      1000ms
      内存
      128MiB
      难度
      5
      标签
      递交数
      314
      已通过
      124
      上传者