Submission #465625

# Submission time Handle Problem Language Result Execution time Memory
465625 2021-08-16T14:55:58 Z alexxela12345 Distributing Candies (IOI21_candies) C++17
11 / 100
5000 ms 12876 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
  int n = c.size();
  if (*min_element(v.begin(), v.end()) >= 0) {

    vector<ll> s(n + 1);
    for (int i = 0; i < (int) l.size(); i++) {
      s[l[i]] += v[i];
      s[r[i] + 1] -= v[i];
    }
    for (int i = 1; i < (int)s.size(); i++) {
      s[i] += s[i - 1];
    }
    s.pop_back();
    vector<int> s2;
    s2.reserve(n);
    for (int i = 0; i < n; i++) {
      int el = min(s[i], (ll) c[i]);
      s2.push_back(el);
    }
    return s2;
  }

  std::vector<int> s(n);
  for (int i = 0; i < (int) l.size(); i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      if (v[i] < 0) {
	s[j] += v[i];
	if (s[j] < 0)
	  s[j] = 0;
      } else {
        s[j] += v[i];
        if (s[j] > c[j])
          s[j] = c[j];
      }
    }
  }
  return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 8800 KB Output is correct
2 Correct 126 ms 12876 KB Output is correct
3 Correct 119 ms 12748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 215 ms 5020 KB Output is correct
3 Correct 205 ms 3764 KB Output is correct
4 Execution timed out 5037 ms 7260 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 540 ms 5016 KB Output is correct
4 Correct 500 ms 2804 KB Output is correct
5 Execution timed out 5023 ms 7256 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 124 ms 8800 KB Output is correct
7 Correct 126 ms 12876 KB Output is correct
8 Correct 119 ms 12748 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 215 ms 5020 KB Output is correct
11 Correct 205 ms 3764 KB Output is correct
12 Execution timed out 5037 ms 7260 KB Time limit exceeded
13 Halted 0 ms 0 KB -