Submission #230572

# Submission time Handle Problem Language Result Execution time Memory
230572 2020-05-10T13:09:48 Z AlexLuchianov Sure Bet (CEOI17_sure) C++14
100 / 100
237 ms 13284 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

using ll = long long;
using ld = long double;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
ld v[1 + nmax], v2[1 + nmax];

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i <= n; i++)
    cin >> v[i] >> v2[i];
  sort(v + 1, v + n + 1);
  reverse(v + 1, v + n + 1);
  sort(v2 + 1, v2 + n + 1);
  reverse(v2 + 1, v2 + n + 1);

  vector<pair<ld,int>> sol;
  ld result = 0;
  for(int i = 1;i <= n; i++){
    v[i] += v[i - 1];
    v2[i] += v2[i - 1];
    sol.push_back({v[i], i});
    sol.push_back({v2[i], -i});
  }
  sort(sol.begin(), sol.end());
  reverse(sol.begin(), sol.end());
  int smin1 = n + 1, smin2 = n + 1;

  for(int i = 0; i < sol.size(); i++){
    if(0 < sol[i].second)
      smin1 = min(smin1, sol[i].second);
    else
      smin2 = min(smin2, -sol[i].second);
    if(smin1 <= n && smin2 <= n)
      result = max(result, ld(1) * sol[i].first - smin1 - smin2);
  }
  cout << setprecision(4) << fixed << result;
  return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < sol.size(); i++){
                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 7 ms 512 KB Output is correct
17 Correct 209 ms 13028 KB Output is correct
18 Correct 214 ms 13284 KB Output is correct
19 Correct 210 ms 13036 KB Output is correct
20 Correct 213 ms 13156 KB Output is correct
21 Correct 237 ms 13028 KB Output is correct
22 Correct 213 ms 13028 KB Output is correct
23 Correct 213 ms 13028 KB Output is correct
24 Correct 210 ms 13028 KB Output is correct
25 Correct 220 ms 13084 KB Output is correct
26 Correct 234 ms 12956 KB Output is correct