Submission #747434

# Submission time Handle Problem Language Result Execution time Memory
747434 2023-05-24T07:39:09 Z vjudge1 Kralj (COCI16_kralj) C++17
140 / 140
599 ms 49304 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 500100;

int n;
int on[MAX];
int moji[MAX], poc[MAX];
int pref[MAX];
vector <int> V[MAX];

int rijesi(int prvi)
{
  int ret = 0;
  set <int> S;

  for (int i=prvi, j=0; j<n; j++, i=(i+1) % n) {
    for (auto it : V[i])
      S.insert(it);

    auto it = S.upper_bound(on[i]);
    if (it == S.end())
      S.erase(S.begin());
    else {
      ret++;
      S.erase(it);
    }
  }

  return ret;
}

int main()
{
  scanf("%d", &n);

  memset(pref, -1, sizeof pref);

  for (int i=0; i<n; i++) {
    scanf("%d", &poc[i]);
    poc[i]--;
  }

  for (int i=0; i<n; i++)
    scanf("%d", &on[i]);

  for (int i=0; i<n; i++) {
    scanf("%d", &moji[i]);
    pref[poc[i]]++;
    V[poc[i]].push_back(moji[i]);
  }

  P minn = P(MAX, MAX);
  for (int i=0; i<n; i++) {
    if (i)
      pref[i] += pref[i-1];

    minn = min(minn, P(pref[i], i));
  }

  int prvi = (minn.Y + 1) % n;
  printf("%d\n", rijesi(prvi));

  return 0;
}

Compilation message

kralj.cpp: In function 'int main()':
kralj.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
kralj.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d", &poc[i]);
      |     ~~~~~^~~~~~~~~~~~~~~
kralj.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d", &on[i]);
      |     ~~~~~^~~~~~~~~~~~~~
kralj.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d", &moji[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 599 ms 43108 KB Output is correct
2 Correct 403 ms 42576 KB Output is correct
3 Correct 508 ms 48532 KB Output is correct
4 Correct 536 ms 49304 KB Output is correct
5 Correct 306 ms 26576 KB Output is correct
6 Correct 291 ms 27120 KB Output is correct
7 Correct 342 ms 29784 KB Output is correct
8 Correct 303 ms 29572 KB Output is correct
9 Correct 394 ms 30456 KB Output is correct
10 Correct 321 ms 27952 KB Output is correct