Submission #121857

# Submission time Handle Problem Language Result Execution time Memory
121857 2019-06-27T06:53:46 Z turbat Sails (IOI07_sails) C++14
90 / 100
1000 ms 2724 KB
    #include <bits/stdc++.h>
    using namespace std;
    #define N 100005
     
    int n, mh;
    long long  sum, cnt[N], s[N], ans, p, uld, avr;
    pair <int, int> mast[N];
     
    void solve (int l){
      if (l > mh) return;
      p = l;
      while (!cnt[p]) p++;
      // cout << l<< endl;
      long long th = mh;
      for (int i = p + 1;i <= th;i++)
        if((s[i] - s[l - 1]) * (p - l + 1) >= (s[p] - s[l - 1]) * (i - l + 1)){
          p = i;
          th = min (th, l - 1 + ((s[th] - s[l - 1]) * (i - l + 1)) / (s[i] - s[l - 1])); 
        }
      sum = s[p] - s[l - 1];
      avr = sum / (p - l + 1);
      uld = sum % (p - l + 1);
      ans += uld * avr;
      ans += (p - l + 1) * avr * (avr - 1) / 2;
      solve (p + 1);
    }
     
    int main (){
      ios_base::sync_with_stdio(NULL);
      cin.tie(NULL);
      cin >> n;
      for (int i = 0;i < n;i++){
        cin >> mast[i].first>> mast[i].second;
        mh = max(mh, mast[i].first);
        cnt[mast[i].first + 1]--;
        cnt[mast[i].first - mast[i].second + 1]++;
      }
      p = 1;
      for (int i = 1;i <= mh;i++) { 
        cnt[i] += cnt[i - 1];
        s[i] = s[i - 1] + cnt[i];
        if(s[i] * p >= s[p] * i)
          p = i;
      }
      avr = s[p] / p;
      uld = s[p] % p;
      ans += uld * avr;
      ans += p * avr * (avr - 1) / 2;
      solve (p + 1);
      cout << ans;
    }
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 540 KB Output is correct
2 Correct 3 ms 1892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 896 KB Output is correct
2 Correct 9 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 1564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2536 KB Output is correct
2 Correct 18 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 2524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 249 ms 2724 KB Output is correct
2 Correct 17 ms 1536 KB Output is correct