Submission #69788

# Submission time Handle Problem Language Result Execution time Memory
69788 2018-08-21T13:37:11 Z Kubalionzzale Roller Coaster Railroad (IOI16_railroad) C++14
0 / 100
436 ms 14824 KB
#include "railroad.h"

#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <map>

int n;
std::pair<int, int> a[200010];
std::multiset<int> set;
//first - output speed, second - index

bool compare(const std::pair<int, int> &lhs, const std::pair<int, int> &rhs)
{
  if (lhs.first != rhs.first)
    return lhs.first < rhs.first;
  else
    return lhs.second < rhs.second;
}

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
  n = (int) s.size();

  for (int i = 0; i < n; ++i)
  {
    a[i].first = s[i];
    a[i].second = t[i];

    set.insert(a[i].second);
  }
  
  long long int ans = 0;

  set.insert(1);

  std::sort(a, a + n, compare);
  for (int i = 0; i < n; ++i)
  {
    bool flag = false;
    
    if (set.find(a[i].second) != set.end())
      flag = true;

    if (flag)
      set.erase(set.find(a[i].second));
    int val = *set.begin();
    ans += val - a[i].first * 1LL;

    set.erase(set.begin());
    if (flag)
      set.insert(a[i].second);
  }

  return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB answer is not correct: -1482254698 instead of 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB answer is not correct: -1482254698 instead of 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 436 ms 14824 KB answer is not correct: -66741691065197 instead of 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB answer is not correct: -1482254698 instead of 0
2 Halted 0 ms 0 KB -