solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0) ret += m;
return ret;
}
long long gcd(long long a, long long b) {
return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
if (b == 0LL) return 1LL;
if (b == 1LL) return mod(a, m);
long long k = mod(exp(a, b / 2, m), m);
if (b & 1LL) {
return mod(a * mod(k * k, m), m);
} else
return mod(k * k, m);
}
int n;
const int N = 300100, MX = 31, inf = 1e9;
int a[N];
int dp[N][MX + 10];
int solve(int id, int j) {
if (id > n) return 0;
int& x = dp[id][j];
if (x != -1) return x;
if (j >= MX) {
return x = solve(id + 1, j - a[id]);
}
x = inf;
if (j > 0) {
int put = min(j, a[id]);
x = solve(id + 1, j - put) + a[id] - put;
}
return x = min(x, solve(id + 1, j + a[id] / 10) + a[id]);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
memset(dp, -1, sizeof(dp));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] /= 100;
}
cout << 100LL * solve(1, 0) << "\n";
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1123456;
int x[MAX];
int n;
int solve(int a, int b) {
int k = 0, j = 0;
for (int i = 1; i <= n; i++) {
if (x[i] == 1000)
a--;
else
b--;
if (x[i] == 1000 && a >= 0 || x[i] == 2000 && b >= 0) {
k += x[i], j += x[i] / 10;
} else {
k += x[i] - min(x[i], j), j -= min(x[i], j);
}
}
return k;
}
int main() {
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", x + i);
sum += x[i];
}
int a = 0, b = 0, ans = sum;
for (int i = 1; i <= n; i++) {
sum -= x[i] / 10 * 11;
if (sum <= 0) break;
if (x[i] == 1000)
a++;
else
b++;
}
ans = min(ans, solve(a, b));
ans = min(ans, solve(a + 1, b));
ans = min(ans, solve(a, b + 1));
ans = min(ans, solve(a - 1, b + 1));
printf("%d\n", ans);
}
| 10 | CPP |
#include <bits/stdc++.h>
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[300000], pp[300000], ip[300000], iq[300000];
int n, i, i_, ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int a;
scanf("%d", &a);
pp[i] = aa[i] = a;
}
for (i = 1; i < n; i++) pp[i] += pp[i - 1];
for (i = 0, i_ = -1; i < n; i++) {
if (aa[i] == 1000) i_ = i;
ip[i] = i_;
}
for (i = n - 1, i_ = n; i >= 0; i--) {
if (aa[i] == 1000) i_ = i;
iq[i] = i_;
}
ans = n * 2000;
for (i = 0; i < n; i++) {
int a, b, x, y;
x = pp[i];
a = x;
b = x / 10;
x = pp[n - 1] - pp[i], y = min(x, b);
a += x - y;
b -= y;
ans = min(ans, a);
if (aa[i] == 2000) {
i_ = ip[i];
if (i_ != -1) {
x = i_ == 0 ? 0 : pp[i_ - 1];
a = x;
b = x / 10;
x = aa[i_], y = min(x, b);
a += x - y;
b -= y;
x = pp[i] - pp[i_];
a += x;
b += x / 10;
x = pp[n - 1] - pp[i], y = min(x, b);
a += x - y;
b -= y;
ans = min(ans, a);
}
i_ = iq[i];
if (i_ != n) {
x = pp[i];
a = x;
b = x / 10;
x = pp[i_ - 1] - pp[i], y = min(x, b);
a += x - y;
b -= y;
x = aa[i_];
a += x;
b += x / 10;
x = pp[n - 1] - pp[i_], y = min(x, b);
a += x - y;
b -= y;
ans = min(ans, a);
}
}
}
printf("%d\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 300007;
const int INF = 2.1e9;
const int MOD = 1e9 + 7;
const double dif = 1e-7;
const double PI = 3.14159265358979323846;
int n, m, k, sum = 0;
int a[maxn], pre[maxn];
bool check(int x) {
int d = sum - k, s = 0, flag1 = 0, flag2 = 0;
if (d > k / 10) return false;
int i;
for (i = n; i >= 1; i--) {
if (s >= d) break;
s += a[i];
if (a[i] == 10) flag1 = 1;
if (a[i] == 20) flag2 = 1;
}
if (pre[i] >= d * 10)
return true;
else if (flag1 && s - d >= 10 && d * 10 - pre[i] <= 10)
return true;
else if (flag2 && s - d >= 10 && d * 10 - pre[i] <= 10) {
for (; i >= 1; i--)
if (a[i] == 10) return pre[i - 1] >= 100;
}
return false;
}
int main(void) {
while (cin >> n) {
pre[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] /= 100;
pre[i] = pre[i - 1] + a[i];
}
sum = pre[n];
k = sum / 11 * 10;
while (!check(k)) k++;
cout << k * 100 << endl;
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, s, cnt, tmp, a[300001];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), s += a[i], cnt += a[i] < 2000;
int tmp = s / 1100;
if (s <= 11000) tmp = (s - a[n]) / 1000;
if (!cnt && tmp & 1) tmp--;
return printf("%d\n", s - tmp * 100), 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXD = 35;
int n, a[300005];
long long f[300005][MAXD + 5];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) a[i] /= 100;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= MAXD; ++j) f[i][j] = 1e18;
f[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= MAXD; ++j) {
if (f[i - 1][j] == 1e18) continue;
if (j >= a[i])
f[i][j - a[i]] = min(f[i][j - a[i]], f[i - 1][j]);
else
f[i][0] = min(f[i][0], f[i - 1][j] + (a[i] - j) * 100);
f[i][min(j + a[i] / 10, MAXD)] =
min(f[i][min(j + a[i] / 10, MAXD)], f[i - 1][j] + a[i] * 100);
}
}
long long ans = 1e18;
for (int i = 0; i <= MAXD; ++i) ans = min(ans, f[n][i]);
printf("%I64d\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
os << "{";
for (auto e : v) os << e << ",";
return os << "}";
}
using uint = unsigned;
using ull = unsigned long long;
template <class t, size_t n>
ostream& operator<<(ostream& os, const array<t, n>& first) {
return os << vc<t>(first.begin(), first.end());
}
template <ll i, class T>
void print_tuple(ostream&, const T&) {}
template <ll i, class T, class H, class... Args>
void print_tuple(ostream& os, const T& t) {
if (i) os << ",";
os << get<i>(t);
print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
os << "{";
print_tuple<0, tuple<Args...>, Args...>(os, t);
return os << "}";
}
template <class t>
void print(t x, ll suc = 1) {
cout << x;
if (suc == 1) cout << "\n";
if (suc == 2) cout << " ";
}
ll read() {
ll i;
cin >> i;
return i;
}
vi readvi(ll n, ll off = 0) {
vi v(n);
for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;
return v;
}
template <class T>
void print(const vector<T>& v, ll suc = 1) {
for (ll i = ll(0); i < ll(v.size()); i++)
print(v[i], i == ll(v.size()) - 1 ? suc : 2);
}
string readString() {
string s;
cin >> s;
return s;
}
template <class T>
T sq(const T& t) {
return t * t;
}
void yes(bool ex = true) {
cout << "Yes"
<< "\n";
if (ex) exit(0);
}
void no(bool ex = true) {
cout << "No"
<< "\n";
if (ex) exit(0);
}
void possible(bool ex = true) {
cout << "Possible"
<< "\n";
if (ex) exit(0);
}
void impossible(bool ex = true) {
cout << "Impossible"
<< "\n";
if (ex) exit(0);
}
constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }
const ll infLL = LLONG_MAX / 3;
const ll inf = infLL;
ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }
ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }
ll popcount(signed t) { return __builtin_popcount(t); }
ll popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(ll i) { return i && (i & -i) == i; }
ll mask(ll i) { return (ll(1) << i) - 1; }
bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }
template <class t>
void mkuni(vc<t>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
ll rand_int(ll l, ll r) {
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<ll>(l, r)(gen);
}
template <class t>
void myshuffle(vc<t>& first) {
for (ll i = ll(0); i < ll(ll(first.size())); i++)
swap(first[i], first[rand_int(0, i)]);
}
template <class t>
ll lwb(const vc<t>& v, const t& first) {
return lower_bound(v.begin(), v.end(), first) - v.begin();
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
ll n;
cin >> n;
vi first = readvi(n);
ll s = 0;
for (ll i = ll(0); i < ll(n); i++) {
first[i] /= 1000;
s += first[i];
}
ll ans = inf;
ll tar = s * 10 / 11;
for (ll u = ll(tar - 10); u < ll(tar + 10); u++) {
if (inc(0, u, s)) {
ll head = 0, cur = 0;
while (head < n && cur + first[head] <= u) cur += first[head++];
vi c(n);
for (ll i = ll(0); i < ll(head); i++) c[i] = 1;
auto upd = [&]() {
ll sum = 0, bon = 0;
for (ll i = ll(0); i < ll(n); i++) {
if (c[i]) {
sum += first[i] * 10;
bon += first[i];
} else {
ll w = min(first[i] * 10, bon);
sum += first[i] * 10 - w;
bon -= w;
}
}
chmin(ans, sum);
};
upd();
{
for (ll i = ll(head); i < ll(n); i++) {
if (first[i] == 1) {
c[i] = 1;
upd();
c[i] = 0;
break;
}
}
}
if (head < n) {
c[head] = 1;
for (ll i = ll(head) - 1; i >= ll(0); i--) {
if (first[i] == 1) {
c[i] = 0;
upd();
c[i] = 1;
break;
}
}
}
}
}
print(ans * 100);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int f(int p1, int r1, int p, int S) {
int a = min(p1 / 10, r1);
int res = p1 + r1 - a;
int rem = p1 / 10 - a;
return res + p - p1 + max(0, S - p - r1 - (p - p1) / 10 - rem);
}
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
vector<int> s(n + 1);
vector<int> v;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
s[i + 1] = s[i] + a[i];
if (a[i] == 1000) v.push_back(i);
}
int S = s.back();
int res = S;
for (int i = 0; i < n; ++i) {
int p = s[i + 1];
res = min(res, p + max(0, S - p - p / 10));
}
if (!v.empty()) {
int s1 = 0;
for (int i = 0; i < n; ++i) {
if (a[i] == 1000) s1 = s[i];
res = min(res, f(s1, 1000, s[i + 1] - 1000, S));
}
for (int i = 0; i < n; ++i) {
int nx = lower_bound(v.begin(), v.end(), i + 1) - v.begin();
if (nx < (int)v.size() && s[i + 1] / 10 >= s[v[nx]] - s[i + 1]) {
res = min(res, f(s[i + 1], s[v[nx]] - s[i + 1], s[i + 1] + 1000, S));
}
}
}
printf("%d\n", res);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int lastone[300005];
int nextone[300005];
long long sum[300005];
vector<int> vt[3];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum[i] = sum[i - 1] + a[i];
lastone[i] = (a[i] == 1000) ? i : lastone[i - 1];
}
for (int i = n; i >= 1; i--) {
nextone[i] = (a[i] == 1000) ? i : nextone[i + 1];
}
long long ans = sum[n];
for (int i = 1; i <= n; i++) {
long long bonus = sum[i] / 10;
long long rem = sum[n] - sum[i];
long long res = sum[i] + rem - min(rem, bonus);
ans = min(ans, res);
if (a[i] == 2000) {
int las = lastone[i];
if (las) {
res = sum[las - 1];
bonus = sum[las - 1] / 10;
res += a[las] - min(a[las] + 0ll, bonus);
bonus -= min(a[las] + 0ll, bonus);
bonus += (sum[i] - sum[las]) / 10;
res += (sum[i] - sum[las]);
rem = sum[n] - sum[i];
res += rem - min(rem, bonus);
ans = min(ans, res);
}
las = nextone[i + 1];
if (las) {
res = sum[i];
bonus = sum[i] / 10;
res += (sum[las - 1] - sum[i]) - min(sum[las - 1] - sum[i], bonus);
bonus -= min(sum[las - 1] - sum[i], bonus);
bonus += a[las] / 10;
res += a[las];
rem = sum[n] - sum[las];
res += rem - min(rem, bonus);
ans = min(ans, res);
}
}
}
printf("%lld\n", ans);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int main() {
memset(a, 0, sizeof(a));
int n = 0, total = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
total += a[i] / 1000;
}
int x = total * 10 / 11;
x = min(x, total - a[n - 1] / 1000);
bool ck = false;
for (int i = 0; i < n - 1; ++i) {
if (a[i] == 1000) {
ck = true;
break;
}
}
if (!ck && x % 2 == 1) {
--x;
}
int res = total * 1000 - x * 100;
printf("%d", res);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
const int INF = 1000000000;
const int MAXV = 40;
int n;
int a[MAXN];
int dp[2][MAXV + 1];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i <= MAXV; i++) dp[0][i] = INF;
dp[0][0] = 0;
int t = 0;
for (int i = 0; i < n; i++, t = 1 - t) {
for (int j = 0; j <= MAXV; j++) dp[1 - t][j] = INF;
for (int j = 0; j <= MAXV; j++)
if (dp[t][j] < INF) {
int nj = min(j + a[i] / 1000, MAXV);
dp[1 - t][nj] = min(dp[1 - t][nj], dp[t][j] + a[i]);
int discount = min(a[i], 100 * j);
nj = j - discount / 100;
dp[1 - t][nj] = min(dp[1 - t][nj], dp[t][j] + a[i] - discount);
}
}
int res = INF;
for (int i = 0; i <= MAXV; i++) res = min(res, dp[t][i]);
printf("%d\n", res);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1e9 + 7;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EOF;
else
return s[it++];
}
bool notend() {
char c = get();
while (c == ' ' || c == '\n') c = get();
if (it > 0) it--;
return c != EOF;
}
} _buff;
inline long long getnum() {
long long r = 0;
bool ng = 0;
char c;
c = _buff.get();
while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
if (c == '-') ng = 1, c = _buff.get();
while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
if (x < 0) putchar('-'), x = -x;
register short a[20] = {}, sz = 0;
while (x) a[sz++] = x % 10, x /= 10;
if (sz == 0) putchar('0');
for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
char c = _buff.get();
while (c == ' ' || c == '\n') c = _buff.get();
return c;
}
int n, a[300111];
long long pre[300111];
int main() {
n = getnum();
long long sum = 0;
for (int i = 1; i <= n; i++) {
a[i] = getnum();
sum += a[i];
pre[i] = pre[i - 1] + a[i];
}
pre[n + 1] = pre[n];
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, min(pre[i] / 10, pre[n] - pre[i]));
}
int ir = 1;
for (int i = 1; i <= n; i++) {
while (i <= n && a[i] == a[ir]) ir++;
long long cur = min(pre[i - 1] / 10, pre[ir - 1] - pre[i - 1]);
long long lft = pre[i - 1] - cur * 10;
int l = ir, r = n;
while (l <= r) {
int mid = l + r >> 1;
if ((pre[mid] - pre[ir - 1] + lft) / 10 < pre[n] - pre[mid])
l = mid + 1;
else
r = mid - 1;
}
long long a1 = min((pre[l] - pre[ir - 1] + lft) / 10, pre[n] - pre[l]);
long long a2 = min((pre[r] - pre[ir - 1] + lft) / 10, pre[n] - pre[r]);
ans = max(ans, max(cur + a1, cur + a2));
}
cout << sum - ans << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = -1;
const int INF = 1.01e9;
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < (n); i++) {
scanf("%d", &a[i]);
}
vector<int> pref;
pref.push_back(0);
for (int i = 0; i < (n); i++) {
pref.push_back(pref.back() + a[i]);
}
auto getSum = [&](int l, int r) { return pref[r] - pref[l]; };
int answer = pref[n];
vector<int> pos;
for (int i = 0; i < (n); i++) {
if (a[i] == 1000 && pos.size() < 12) {
pos.push_back(i);
}
}
pos.push_back(-1);
auto solve = [&](int when) {
int bonus = 0;
int res = 0;
for (int i = 0; i < (n); i++) {
if (when == i) {
int x = min(a[i], bonus);
bonus -= x;
} else {
res += a[i] / 10;
bonus += a[i] / 10;
if (getSum(i + 1, n) < bonus) {
answer = min(answer, pref[n] - (res - (bonus - getSum(i + 1, n))));
break;
}
}
answer = min(answer, pref[n] - res);
}
};
for (auto x : pos) {
solve(x);
}
int opt = (pref[n] / 11) / 100 * 100;
int cur = n - 1;
int curSum = 0;
bool sawOne = 0;
for (; cur >= 0 && curSum + a[cur] <= opt; cur--) {
curSum += a[cur];
sawOne |= a[cur] == 1000;
}
if (sawOne) {
answer = min(answer, pref[n] - opt);
}
cout << answer << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
return i;
}
template <typename T>
std::ostream& operator<<(std::ostream& o, const vector<T>& t) {
for (size_t i = 0; i < t.size(); ++i) {
o << t[i] << " \n"[i == t.size() - 1];
}
return o;
}
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
auto fraclt = [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
return (long long)a.first * b.second < (long long)b.first * a.second;
};
struct cmpfrac {
bool operator()(const std::pair<int, int>& a,
const std::pair<int, int>& b) const {
return (long long)a.first * b.second < (long long)b.first * a.second;
}
};
template <typename T>
bool in(T a, T b, T c) {
return a <= b && b < c;
}
unsigned int logceil(long long first) {
unsigned int b = 0;
while (first) {
first >>= 1;
++b;
}
return b;
}
namespace std {
template <typename T, typename U>
struct hash<pair<T, U>> {
hash<T> t;
hash<U> u;
size_t operator()(const pair<T, U>& p) const {
return t(p.first) ^ (u(p.second) << 7);
}
};
} // namespace std
template <typename T, typename F>
T bsh(T l, T h, const F& f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
l = m + 1;
r = m;
} else {
h = m - 1;
}
}
return r;
}
template <typename T, typename F>
T bsl(T l, T h, const F& f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
h = m - 1;
r = m;
} else {
l = m + 1;
}
}
return r;
}
template <typename T>
T gcd(T a, T b) {
if (a < b) swap(a, b);
return b ? gcd(b, a % b) : a;
}
template <typename T>
class vector2 : public vector<vector<T>> {
public:
vector2() {}
vector2(size_t a, size_t b, T t = T())
: vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T>
class vector3 : public vector<vector<vector<T>>> {
public:
vector3() {}
vector3(size_t a, size_t b, size_t c, T t = T())
: vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, t))) {}
};
template <typename T>
struct bounded_priority_queue {
inline bounded_priority_queue(unsigned int X) : A(X), B(0) {}
inline void push(unsigned int L, T V) {
B = max(B, L);
A[L].push(V);
}
inline const T& top() const { return A[B].front(); }
inline void pop() {
A[B].pop();
while (B > 0 && A[B].empty()) --B;
}
inline bool empty() const { return A[B].empty(); }
inline void clear() {
B = 0;
for (auto& a : A) a = queue<T>();
}
private:
vector<queue<T>> A;
unsigned int B;
};
constexpr int mx = 33;
class TaskD {
public:
void solve(istream& cin, ostream& cout) {
int N;
cin >> N;
vector<int> D(mx, MOD), E(mx);
D[0] = 0;
for (int i = 0; i < N; ++i) {
fill(E.begin(), E.end(), MOD);
int a;
cin >> a;
int b = a / 1000;
int c = a / 100;
for (int j = 0; j < mx; ++j) {
if (j >= c)
E[j - c] = min(E[j - c], D[j]);
else
E[0] = min(E[0], D[j] + (c - j));
if (j + b < mx) E[j + b] = min(E[j + b], D[j] + c);
}
swap(D, E);
}
int ans = *min_element(D.begin(), D.end());
cout << 100LL * ans << endl;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
TaskD solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
const int L = 30;
const int oo = 1e9;
int N, A[maxn];
int dp[L + 5][maxn];
inline void change(int &ret, int v) {
if (ret > v) ret = v;
}
int solve() {
for (int i = (0), _i = (L + 1); i <= _i; i++)
for (int j = (0), _j = (N); j <= _j; j++) dp[i][j] = oo;
dp[0][0] = 0;
for (int i = (0), _i = (N - 1); i <= _i; i++)
for (int j = (0), _j = (L + 1); j <= _j; j++)
if (dp[j][i] != oo) {
int cost = A[i + 1];
if (j < L) change(dp[j + cost / 10][i + 1], dp[j][i] + cost);
for (int k = (1), _k = (min(cost, j)); k <= _k; k++)
change(dp[j - k][i + 1], dp[j][i] + cost - k);
}
int ans = oo;
for (int i = (0), _i = (L + 1); i <= _i; i++)
if (dp[i][N] != oo) change(ans, dp[i][N]);
return ans;
}
int main() {
for (; scanf("%d", &N) != EOF;) {
for (int i = (1), _i = (N); i <= _i; i++) scanf("%d", &A[i]);
for (int i = (1), _i = (N); i <= _i; i++) A[i] /= 100;
int ans = solve();
printf("%d\n", ans * 100);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, ai, summ;
vector<long long> data;
vector<long long> sums, nexts, prevs;
bool checker(long long mid) {
long long ww = mid;
if (mid * 11 > summ) return false;
long long gr;
for (long long i = n - 1; i >= 0; i--) {
if (data[i] > mid) {
gr = i;
break;
}
mid -= data[i];
}
if (mid == 0) return true;
if (data[gr] == 1000) return true;
if (data[gr] == 2000 && mid > 1000) return true;
if (sums[gr] >= 10 * ww) return true;
if (nexts[gr] != n - 1 && nexts[gr] != -1) return true;
if (prevs[gr] == -1) return false;
long long ind = prevs[gr];
if (sums[ind] >= 10 * (mid)) return true;
return false;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
summ = 0;
sums.push_back(summ);
for (long long i = 0; i < n; i++) {
cin >> ai;
summ += ai;
sums.push_back(summ);
data.push_back(ai);
}
if (data[0] == 1000)
prevs.push_back(0);
else
prevs.push_back(-1);
for (long long i = 0; i < n; i++) {
nexts.push_back(-1);
}
if (data[n - 1] == 1000)
nexts[n - 1] = n - 1;
else
nexts[n - 1] = -1;
for (long long i = 1; i < n; i++) {
if (data[i] == 1000)
prevs.push_back(i);
else
prevs.push_back(prevs[i - 1]);
}
for (long long i = n - 2; i >= 0; i--) {
if (data[i] == 1000)
nexts[i] = i;
else
nexts[i] = nexts[i + 1];
}
long long left = 0;
long long right = summ / 100 + 2;
while (right - left > 1) {
long long mid = (left + right) / 2;
bool res = checker(100 * mid);
if (res)
left = mid;
else
right = mid;
}
cout << summ - left * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7, inf = 1e9 + 7;
int a[N], dp[2][50], now, n;
void gmin(int &a, int b) {
if (a > b) a = b;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", a + i), a[i] /= 100;
now = 0;
for (int i = 1; i <= 40; ++i) dp[now][i] = inf;
for (int i = 1; i <= n; ++i) {
now ^= 1;
for (int j = 0; j <= 40; ++j) dp[now][j] = inf;
for (int j = 0; j <= 40; ++j) {
gmin(dp[now][j + a[i] / 10], dp[now ^ 1][j] + a[i]);
gmin(dp[now][j - a[i] + max(a[i] - j, 0)],
dp[now ^ 1][j] + max(a[i] - j, 0));
}
}
int ans = inf;
for (int i = 0; i <= 40; ++i) gmin(ans, dp[now][i]);
printf("%d00\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 10;
const int MAXY = 40;
int N;
long long DP[MAXN][MAXY + 1];
void Work() {
scanf("%d", &N);
memset(DP, 1, sizeof(DP));
DP[0][0] = 0;
for (int i = 1; i <= N; i++) {
int ai, add;
scanf("%d", &ai);
ai = ai / 100;
add = ai / 10;
for (int j = 0; j <= MAXY; j++) {
if (j + add <= MAXY)
DP[i][j + add] = min(DP[i][j + add], DP[i - 1][j] + ai);
int use = min(j, ai);
DP[i][j - use] = min(DP[i][j - use], DP[i - 1][j] + ai - use);
}
}
long long Ans = 10000000000000000LL;
for (int j = 0; j <= MAXY; j++) Ans = min(Ans, DP[N][j] * 100LL);
printf("%I64d\n", Ans);
}
int main() {
Work();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
long long res = 1LL << 55;
vector<long long> psum(n + 1);
for (int i = 0; i < n; i++) psum[i + 1] = psum[i] + a[i];
for (int i = 0; i <= n; i++) {
long long p0 = psum[i];
long long p1 = max(0LL, psum[n] - psum[i] - p0 / 10);
res = min(res, p0 + p1);
}
int last = -1;
for (int i = 0; i <= n; i++) {
long long p0 = ((last == -1) ? 0LL : psum[last]) - psum[0];
long long p1 = max(0LL, 1000 - p0 / 10);
long long p2 = psum[i] - psum[last + 1];
long long p3 =
max(0LL, psum[n] - psum[i] - (p0 / 10 - (1000 - p1) + p2 / 10));
if (last >= 0) res = min(res, p0 + p1 + p2 + p3);
if (i < n && a[i] == 1000) last = i;
}
vector<int> nex(n + 1, n);
for (int i = n - 1; i >= 0; i--) {
nex[i] = nex[i + 1];
if (a[i] == 1000) nex[i] = i;
}
for (int i = 0; i <= n; i++) {
if (nex[i] == n) break;
long long p0 = psum[i];
long long p1 = max(0LL, psum[nex[i]] - psum[i] - p0 / 10);
long long p2 = 1000;
long long p3 =
max(0LL, psum[n] - psum[nex[i] + 1] -
(p0 / 10 - (psum[nex[i]] - psum[i] - p1) + p2 / 10));
res = min(res, p0 + p1 + p2 + p3);
}
cout << res << "\n";
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
if (a < b) a = b;
}
const int maxn = 300000 + 100;
int n;
int a[maxn], s[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0, i__n = (int)(n); i < i__n; ++i)
cin >> a[i], s[i + 1] = s[i] + a[i];
int f = s[n] / 11 / 100;
int pos = lower_bound(s, s + n + 1, f * 1000) - s;
if (s[pos] > f * 1000 && pos == n) f--;
cout << s[n] - f * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int Stv[1 << 8];
inline int read() {
int f = 1, res = 0, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
return f * res;
}
int n, f[2][35];
int main() {
n = read();
memset(f, 127, sizeof(f));
int INF = f[0][0];
f[0][0] = 0;
int now, pre;
for (int i = 1, _Lim = n; i <= _Lim; i++) {
now = i & 1, pre = now ^ 1;
memset(f[now], 127, sizeof(f[now]));
int val = read() / 100, tik = val / 10;
for (int j = 0, _Lim = 30 - tik; j <= _Lim; j++)
f[now][j + tik] = min(f[now][j + tik], f[pre][j] + val);
for (int j = 0, _Lim = 30; j <= _Lim; j++)
f[now][j - min(j, val)] =
min(f[now][j - min(j, val)], f[pre][j] + val - min(j, val));
}
int Ans = INF;
for (int i = 0, _Lim = 30; i <= _Lim; i++) Ans = min(Ans, f[now][i]);
printf("%d\n", Ans * 100);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5;
long long n, a[N], dp[N][40];
void solveTestCase() {
for (long long i = 0; i < N; i++) {
for (long long j = 0; j < 40; j++) dp[i][j] = 1e18;
}
cin >> n;
for (long long i = 0; i < n; i++) cin >> a[i];
if (a[0] == 1000)
dp[0][1] = 1000;
else
dp[0][2] = 2000;
for (long long i = 1; i < n; i++) {
if (a[i] == 1000) {
for (long long j = 1; j < 40; j++) dp[i][j] = dp[i - 1][j - 1] + 1000;
for (long long j = 0; j < 30; j++)
dp[i][j] = min(dp[i][j], dp[i - 1][j + 10]);
for (long long j = 1; j <= 10; j++)
dp[i][0] = min(dp[i][0], dp[i - 1][j] + 1000 - j * 100);
} else {
for (long long j = 2; j < 40; j++) dp[i][j] = dp[i - 1][j - 2] + 2000;
for (long long j = 0; j < 20; j++)
dp[i][j] = min(dp[i][j], dp[i - 1][j + 20]);
for (long long j = 1; j <= 20; j++)
dp[i][0] = min(dp[i][0], dp[i - 1][j] + 2000 - j * 100);
}
}
cout << min({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long t = 1;
while (t--) solveTestCase();
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int n;
long long a[MAXN], dp[MAXN][35];
inline void chkmin(long long& x, long long y) {
if (y < x) x = y;
}
int main() {
scanf("%d", &n);
for (long long i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
memset(dp, 127 / 2, sizeof(dp));
dp[0][0] = 0;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j <= 30; j++) {
chkmin(dp[i + 1][j + a[i] / 1000], dp[i][j] + a[i]);
chkmin(dp[i + 1][j - min(j, a[i] / 100)],
dp[i][j] + a[i] - 100 * min(j, a[i] / 100));
}
}
long long ans = LLONG_MAX;
for (long long j = 0; j <= 30; j++) {
ans = min(ans, dp[n][j]);
}
printf("%lld\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
char ch;
int n, a[300002];
long long f[300002][41], ans;
inline void read(int &x) {
x = 0;
do {
ch = getchar();
} while (ch < '0' || '9' < ch);
do {
x = x * 10 + ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
}
inline void read(long long &x) {
x = 0;
do {
ch = getchar();
} while (ch < '0' || '9' < ch);
do {
x = x * 10 + ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
}
inline void updata(long long &x, const long long &y) { x = min(x, y); }
int main(void) {
read(n);
for (int i = (1); i <= (n); i++) read(a[i]), a[i] /= 100;
memset(f, 0x3f, sizeof(f));
f[0][0] = 0;
for (int i = 0; i < (n); i++)
for (int j = 0; j < (41); j++) {
if (j + a[i + 1] / 10 <= 40)
updata(f[i + 1][j + a[i + 1] / 10], f[i][j] + a[i + 1]);
updata(f[i + 1][max(0, j - a[i + 1])], f[i][j] + max(0, a[i + 1] - j));
}
ans = 0x3f3f3f3f;
for (int i = 0; i < (41); i++) updata(ans, f[n][i]);
cout << ans * 100;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 4, M = 31, INF = 1e9;
int n, a[N], dp[N][M];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], a[i] /= 100;
for (int i = 0; i <= n; i++)
for (int j = 0; j < M; j++) dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < M; j++) {
dp[i + 1][max(j - a[i + 1], 0)] =
min(dp[i][j] + max(a[i + 1] - j, 0), dp[i + 1][max(j - a[i + 1], 0)]);
if (j + a[i] / 10 < M)
dp[i + 1][j + a[i + 1] / 10] =
min(dp[i][j] + a[i + 1], dp[i + 1][j + a[i + 1] / 10]);
}
cout << dp[n][0] * 100;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
char ch;
int n, a[300002];
long long f[300002][41], ans;
inline void read(int &x) {
x = 0;
do {
ch = getchar();
} while (ch < '0' || '9' < ch);
do {
x = x * 10 + ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
}
inline void read(long long &x) {
x = 0;
do {
ch = getchar();
} while (ch < '0' || '9' < ch);
do {
x = x * 10 + ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
}
inline void updata(long long &x, const long long &y) { x = min(x, y); }
int main(void) {
read(n);
for (int i = (1); i <= (n); i++) read(a[i]), a[i] /= 100;
memset(f, 0x3f, sizeof(f));
f[0][0] = 0;
for (int i = 0; i < (n); i++)
for (int j = 0; j < (41); j++) {
if (j + a[i + 1] / 10 <= 40)
updata(f[i + 1][j + a[i + 1] / 10], f[i][j] + a[i + 1]);
updata(f[i + 1][max(0, j - a[i + 1])], f[i][j] + max(0, a[i + 1] - j));
}
ans = 0x3f3f3f3f;
for (int i = 0; i < (41); i++) updata(ans, f[n][i]);
printf("%d", ans * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, sum, ans, aans, now;
int main() {
cin >> n;
for (int x = 1; x <= n; x++)
cin >> now, sum += now / 1000, ans += (now == 1000);
if (sum <= 11)
aans = sum - now / 1000;
else
aans = sum * 10 / 11;
cout << sum * 1000 - (aans - (!ans && aans % 2 == 1)) * 100 << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N;
int A[303030];
signed long long dp[303030][32];
void solve() {
int i, j, k, l, r, x, y;
string s;
scanf("%d", &N);
for (i = 0; i < (N); i++) scanf("%d", &A[i]), A[i] /= 100;
for (i = 0; i < (N + 1); i++)
for (j = 0; j < (32); j++) dp[i][j] = 1LL << 60;
dp[0][0] = 0;
for (i = 0; i < (N); i++) {
for (j = 0; j < (32); j++)
if (dp[i][j] < 1LL << 60) {
for (int use = 0; use <= min(j, A[i]); use++) {
dp[i + 1][j - use] = min(dp[i + 1][j - use], dp[i][j] + A[i] - use);
}
if (j < 30)
dp[i + 1][j + A[i] / 10] =
min(dp[i + 1][j + A[i] / 10], dp[i][j] + A[i]);
}
}
signed long long mi = 1LL << 60;
for (i = 0; i < (32); i++) mi = min(mi, dp[N][i] * 100);
cout << mi << endl;
}
int main(int argc, char** argv) {
string s;
int i;
if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int n, ans;
int a[N], f[N][35];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
memset(f, 60, sizeof f);
ans = f[0][0];
f[0][0] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j <= 30; j++) {
f[i + 1][j + a[i] / 1000] =
min(f[i + 1][j + a[i] / 1000], f[i][j] + a[i]);
f[i + 1][j - min(j, a[i] / 100)] =
min(f[i + 1][j - min(j, a[i] / 100)],
f[i][j] + a[i] - 100 * min(a[i] / 100, j));
}
for (int i = 0; i <= 30; i++) ans = min(ans, f[n][i]);
printf("%d\n", ans);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[300300];
int total = 0, cnt1 = 0, cnt2 = 0;
int before[300300];
inline int countBonus(int x, int y) {
return min(x * 100 + y * 200, (cnt1 - x) * 1000 + (cnt2 - y) * 2000);
}
int main() {
int maxBonus = 0, current;
int l, r, mid1, mid2, b1, b2;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == 1000) {
cnt1++;
before[cnt1] = cnt2;
} else
cnt2++;
total += a[i];
}
for (int i = 0; i <= cnt1; i++) {
if (i == cnt1 && a[n] == 1000) continue;
l = before[max(i - 1, 0)];
r = cnt2 - (a[n] == 2000);
while (r - l + 1 >= 4) {
mid1 = l + (r - l) / 3;
mid2 = l + 2 * (r - l) / 3;
b1 = countBonus(i, mid1);
b2 = countBonus(i, mid2);
if (b1 < b2)
l = mid1;
else
r = mid2;
}
current = 0;
for (int j = l; j <= r; j++) current = max(current, countBonus(i, j));
maxBonus = max(maxBonus, current);
}
printf("%d\n", total - maxBonus);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const long long inf = 1e18;
int n;
int a[N];
int dp[N];
int dpn[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i <= 30; i++) {
dp[i] = int(1e9);
dpn[i] = int(1e9);
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 30; j++) {
dpn[j + a[i] / 1000] = min(dpn[j + a[i] / 1000], dp[j] + a[i]);
int jj = min(a[i] / 100, j);
dpn[j - jj] = min(dpn[j - jj], dp[j] + a[i] - jj * 100);
}
for (int j = 0; j <= 30; j++) {
dp[j] = dpn[j];
dpn[j] = int(1e9);
}
}
int ans = int(1e9);
for (int i = 0; i <= 30; i++) {
ans = min(ans, dp[i]);
}
cout << ans;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXD = 31;
int n, a[300005];
long long f[300005][MAXD + 5];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) a[i] /= 100;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= MAXD; ++j) f[i][j] = 1e18;
f[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= MAXD; ++j) {
if (f[i - 1][j] == 1e18) continue;
if (j >= a[i])
f[i][j - a[i]] = min(f[i][j - a[i]], f[i - 1][j]);
else
f[i][0] = min(f[i][0], f[i - 1][j] + (a[i] - j) * 100);
f[i][min(j + a[i] / 10, MAXD)] =
min(f[i][min(j + a[i] / 10, MAXD)], f[i - 1][j] + a[i] * 100);
}
}
long long ans = 1e18;
for (int i = 0; i <= MAXD; ++i) ans = min(ans, f[n][i]);
printf("%I64d\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = getchar();
int x = 0, op = 1;
while (ch < '0' || '9' < ch) {
if (ch == '-') op = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
int x = 0;
}
return op * x;
}
const int maxn = 300009;
int f[maxn][35], a[maxn], n, ans = 2e9;
void update(int &a, int b) {
if (b < a) a = b;
}
int main() {
n = read();
for (int i = (1); i <= (n); i++) {
a[i] = read();
a[i] /= 100;
}
memset(f, 0x3f, sizeof f);
f[0][0] = 0;
for (int i = (0); i <= (n); i++)
for (int j = (0); j <= (31); j++) {
if (j + a[i] / 10 <= 31)
update(f[i + 1][j + a[i + 1] / 10], f[i][j] + a[i + 1]);
if (j >= a[i + 1])
update(f[i + 1][j - a[i + 1]], f[i][j]);
else
update(f[i + 1][0], f[i][j] + a[i + 1] - j);
}
for (int i = (0); i <= (31); i++) update(ans, f[n][i]);
printf("%d00\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool mini(A &x, const B &y) {
if (y < x) {
x = y;
return true;
}
return false;
}
template <typename A, typename B>
bool maxi(A &x, const B &y) {
if (y > x) {
x = y;
return true;
}
return false;
}
class fastio {
public:
fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} __fastio;
long long a[300500];
long long dp[300500][50];
long long was[300500][25];
int main() {
long long ans = 0;
int n;
cin >> n;
for (auto i = 0; i < n; i++) cin >> a[i];
long long bal = 0;
for (auto i = 0; i < n + 1; i++) {
for (auto j = 0; j < 50; j++) {
dp[i][j] = 1e18;
}
}
dp[0][0] = 0;
for (auto i = 0; i < n; i++) {
for (auto j = 0; j < 48; j++) {
if (j > a[i] / 100) {
dp[i + 1][j - a[i] / 100] = min(dp[i + 1][j - a[i] / 100], dp[i][j]);
} else {
dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + a[i] - j * 100);
}
dp[i + 1][j + a[i] / 1000] =
min(dp[i + 1][j + a[i] / 1000], dp[i][j] + a[i]);
}
}
ans = 1e18;
for (auto j = 0; j < 50; j++) {
ans = min(dp[n][j], ans);
}
cout << ans;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 300005;
const long long inf = (1e15);
long long f[N][50], n, a[N];
signed main() {
cin >> n;
for (register long long i = (1); i <= (n); ++i) cin >> a[i], a[i] /= 100;
memset(f, 0x3f, sizeof(f));
f[0][0] = 0;
for (register long long i = (1); i <= (n); ++i)
for (register long long j = (0); j <= (40); ++j) {
if (j + a[i] / 10 <= 40)
f[i][j + a[i] / 10] = min(f[i][j + a[i] / 10], f[i - 1][j] + a[i]);
f[i][j - min(a[i], j)] =
min(f[i][j - min(a[i], j)], f[i - 1][j] + a[i] - min(a[i], j));
}
long long ans = inf;
for (register long long j = (0); j <= (40); ++j) ans = min(ans, f[n][j]);
cout << ans * 100ll << '\n';
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 0, M = 0;
int read() {
char c;
int num, f = 1;
while (c = getchar(), !isdigit(c))
if (c == '-') f = -1;
num = c - '0';
while (c = getchar(), isdigit(c)) num = num * 10 + c - '0';
return num * f;
}
int n, f[300009][31];
void up(int &x, int y) { x > y ? x = y : 0; }
int main() {
memset(f, 0x3f, sizeof(f));
n = read();
int x = read() / 100;
f[1][x / 10] = x;
for (int i = 1; i < n; i++) {
x = read() / 100;
for (int j = 0; j <= 30; j++)
if (f[i][j] != 0x3f3f3f3f) {
if (j + x / 10 <= 30) up(f[i + 1][j + x / 10], f[i][j] + x);
if (j >= x)
up(f[i + 1][j - x], f[i][j]);
else
up(f[i + 1][0], f[i][j] + x - j);
}
}
int ans = 0x3f3f3f3f;
for (int i = 0; i <= 30; i++) ans = min(ans, f[n][i]);
printf("%d\n", ans * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void smin(T &a, U b) {
if (a > b) a = b;
}
const long long mod = 1000000007;
const int N = 3e5 + 10;
const int M = 2e6;
int n, a[N], dp[N][66];
int main() {
cin >> n;
for (int i = 0; i <= n - 1; i++) {
scanf("%d", a + i);
a[i] /= 100;
}
memset(dp, 63, sizeof dp);
dp[0][0] = 0;
for (int i = 0; i < n; ++i)
for (int b = 0; b <= 60; ++b) {
{ smin(dp[i + 1][a[i] / 10 + b], dp[i][b] + a[i]); }
{
for (int first = 1; first <= min(b, a[i]); ++first)
smin(dp[i + 1][b - first], dp[i][b] + a[i] - first);
}
}
int res = mod;
for (int b = 0; b <= 60; ++b) smin(res, dp[n][b]);
cout << res << "00\n";
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, tot, tmp, sum, a[5000005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == 1000)
tot++, sum++;
else
sum += 2;
}
int tmp = 10 * sum / 11;
if (sum <= 11) tmp = sum - a[n] / 1000;
if (!tot && tmp & 1) tmp--;
printf("%d\n", 1000 * sum - tmp * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int n, sum, tot, ans;
int a[400400];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
sum += a[i] / 1000;
tot += (a[i] == 1000);
}
int temp = sum * 10 / 11;
if (sum <= 11) temp = sum - a[n] / 1000;
if (!tot && temp % 2 == 1) temp--;
printf("%d\n", sum * 1000 - temp * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5, mod = 1e9 + 7;
int koszt[31], tmp[31];
int main() {
int a, b, c, d, e, f, g, z, k, n, m, q;
scanf("%d", &n);
for (a = 1; a <= 30; a++) koszt[a] = 1000000000;
while (n--) {
scanf("%d", &a);
if (a == 1000) {
for (b = 0; b <= 30; b++) tmp[b] = 1000000000;
for (b = 1; b <= 30; b++) tmp[b] = koszt[b - 1] + 1000;
for (b = 0; b <= 30; b++)
for (c = b + 1; c <= 30 && c - b <= 10; c++)
tmp[b] = min(tmp[b], koszt[c] + 1000 - (c - b) * 100);
} else {
for (b = 0; b <= 30; b++) tmp[b] = 1000000000;
for (b = 2; b <= 30; b++) tmp[b] = koszt[b - 2] + 2000;
for (b = 0; b <= 30; b++)
for (c = b + 1; c <= 30 && c - b <= 20; c++)
tmp[b] = min(tmp[b], koszt[c] + 2000 - (c - b) * 100);
}
for (b = 0; b <= 30; b++) koszt[b] = tmp[b];
}
b = koszt[0];
for (a = 1; a <= 30; a++) b = min(b, koszt[a]);
printf("%d", b);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
;
}
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
} // namespace std
const int INF = 7e8;
int n;
int ar[300005];
int sum[300005];
vector<int> Tpos, Opos;
int solve1(int a, int b, int A, int B) {
if (B == INF) return INF;
if (b == INF) return INF;
int Tlen = B - b;
int tmp = sum[b] * 1000;
int pt = sum[b] * 100;
int Trange = Tlen * 2000;
tmp += max(0, Trange - pt);
pt -= min(Trange, pt);
tmp += 1000;
pt += 100;
int rest = (sum[n] - sum[B + 1]) * 1000;
tmp += max(0, rest - pt);
return tmp;
}
int solve2(int a, int b, int A, int B) {
if (a == -1) return INF;
if (A == -1) return INF;
int Tlen = a - A;
int tmp = sum[A] * 1000;
int pt = sum[A] * 100;
tmp += max(0, 1000 - pt);
pt -= min(pt, 1000);
int Trange = Tlen * 2000;
tmp += Trange;
pt += Tlen * 200;
int rest = (sum[n] - sum[a + 1]) * 1000;
tmp += max(0, rest - pt);
return tmp;
}
int main() {
cin >> n;
Opos.push_back(-1);
Tpos.push_back(-1);
for (int i = 0; i < (n); ++i) {
int a;
scanf("%d", &a);
ar[i] = a / 1000;
if (ar[i] == 1)
Opos.push_back(i);
else
Tpos.push_back(i);
}
Tpos.push_back(INF);
Opos.push_back(INF);
for (int i = 0; i < (n); ++i) sum[i + 1] = sum[i] + ar[i];
int res = INF;
for (int i = 0; i < (n + 1); ++i) {
int tmp = sum[i] * 1000;
int pt = sum[i] * 100;
int rest = (sum[n] - sum[i]) * 1000;
tmp += max(0, rest - pt);
chmin(res, tmp);
}
int prev = res;
for (int i = 0; i < ((int)Tpos.size() - 1); ++i) {
int a = Tpos[i], b = Tpos[i + 1];
int B = *lower_bound((Opos).begin(), (Opos).end(), b);
int A = *(--lower_bound((Opos).begin(), (Opos).end(), a));
int X = solve1(a, b, A, B);
int Y = solve2(a, b, A, B);
chmin(res, X);
chmin(res, Y);
}
cout << res << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int n, pos1Size = 0, pos2Size = 0;
int ar[N], pos1[N], pos2[N];
struct Node {
int S, M;
Node() {}
Node(int S, int M) : S(S), M(M) {}
};
Node st[3 * N];
void Update(int k, int v) {
k += (1 << 19);
st[k] = Node(v, v);
while (k > 1) {
k >>= 1;
st[k].M = min(st[k << 1].M, st[k << 1].S + st[k << 1 | 1].M);
st[k].S = st[k << 1].S + st[k << 1 | 1].S;
}
}
bool Check(int m) {
int p1 = 0, p2 = 0;
for (int i = 1; i <= n; ++i) Update(i, -ar[i]);
int a = 0;
int b = (m - 1000 * a) / 2000;
b = min(b, pos2Size);
while (p2 + 1 <= b && p2 + 1 <= pos2Size) {
Update(pos2[p2 + 1], 200);
++p2;
}
int cost = (m - 1000 * a - 2000 * b);
Update(0, cost);
if (st[1].M >= 0) return true;
for (int a = 1; a <= pos1Size; ++a) {
if (m < 1000 * a) return false;
int b = (m - 1000 * a) / 2000;
b = min(b, pos2Size);
int cost = (m - 1000 * a - 2000 * b);
Update(0, cost);
while (p1 + 1 <= a && p1 + 1 <= pos1Size) {
Update(pos1[p1 + 1], 100);
++p1;
}
while (p2 > b && p2 > 0) {
Update(pos2[p2], -ar[pos2[p2]]);
--p2;
}
if (st[1].M >= 0) return true;
}
return false;
}
void Read(int &n) {
n = 0;
char c;
do {
c = getchar();
} while (!isdigit(c));
do {
n = n * 10 + c - 48;
c = getchar();
} while (isdigit(c));
}
int main() {
Read(n);
for (int i = 1; i <= n; ++i) Read(ar[i]);
for (int i = 1; i <= n; ++i)
if (ar[i] == 1000)
pos1[++pos1Size] = i;
else
pos2[++pos2Size] = i;
int l = 1, r = 2000 * N, f = -1;
while (l <= r) {
int m = (l + r) >> 1;
if (Check(m) == true) {
f = m;
r = m - 1;
} else
l = m + 1;
}
printf("%d", f);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
a = (a + b);
if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
template <class T>
bool domin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool domax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
int gi() {
int a;
scanf("%d", &a);
return a;
}
long long gll() {
long long a;
scanf("%lld", &a);
return a;
}
int ans[2][1007];
int main() {
int v = 1000000007;
fill_n(ans[0], 1007, v);
fill_n(ans[1], 1007, v);
ans[0][0] = 0;
int n = gi(), ix, nx;
for (int i = 0; i < n; i++) {
int x = gi() / 100;
int bo = x / 10;
ix = (i & 1);
nx = ix ^ 1;
fill_n(ans[nx], 1007, v);
for (int j = 0; j < 1007; j++)
if (ans[ix][j] < 1000000007) {
if (j < x) {
domin(ans[nx][j + bo], ans[ix][j] + x);
domin(ans[nx][0], ans[ix][j] + x - j);
} else if (j < 1007 - 100) {
domin(ans[nx][j - x], ans[ix][j]);
domin(ans[nx][j + bo], ans[ix][j] + x);
} else {
domin(ans[nx][j - x], ans[ix][j]);
}
}
}
int fa = 1000000007;
for (int i = 0; i < 1007; i++) {
domin(fa, ans[nx][i]);
}
cout << fa * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXC = 305;
const int MAXN = 300005;
const int INF = 1000000000;
int A[MAXN], dp[2][MAXC];
int main(int argc, char const *argv[]) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &A[i]);
A[i] /= 100;
}
for (int i = 0; i < MAXC; ++i) {
dp[0][i] = dp[1][i] = INF;
}
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
int curr = i % 2, prev = (i + 1) % 2;
for (int j = 0; j < MAXC; ++j) {
int nv = j + A[i] / 10;
if (nv < MAXC) {
dp[curr][nv] = min(dp[curr][nv], dp[prev][j] + A[i]);
}
int to_sub = min(j, A[i]);
nv = j - to_sub;
dp[curr][nv] = min(dp[curr][nv], dp[prev][j] + A[i] - to_sub);
dp[prev][j] = INF;
}
}
int ans = INF;
for (int i = 0; i < MAXC; ++i) {
ans = min(ans, dp[n % 2][i]);
}
printf("%d\n", ans * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &x, T y) {
return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
return x > y ? x = y, true : false;
}
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n;
long long a[300005], s[300005], lst[300005];
int main() {
n = readint();
for (int i = 1; i <= n; i++) a[i] = readint();
for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
for (int i = 1; i <= n; i++) {
lst[i] = lst[i - 1];
if (a[i] == 1000) lst[i] = i;
}
long long ans = 1ll << 60;
for (int i = 1; i <= n; i++) {
long long tmp = s[i], now = s[i] / 10;
chkmin(ans, tmp + max(0ll, s[n] - s[i] - now));
if (a[i] == 1000) {
for (int j = i - 1; j >= 1; j--) {
if (a[j] != 2000) break;
tmp = s[j - 1] + 1000, now = (s[j - 1] + 1000) / 10;
if (s[j - 1] / 10 >= 2000ll * (i - j))
now -= 2000ll * (i - j);
else
tmp += 2000ll * (i - j) - s[j - 1] / 10, now -= s[j - 1] / 10;
chkmin(ans, tmp + max(0ll, s[n] - s[i] - now));
}
} else {
int pl = lst[i];
if (!pl) continue;
tmp = s[i] - 1000, now = (s[i] - 1000) / 10;
if (s[pl - 1] / 10 >= 1000)
now -= 1000;
else
tmp += 1000 - s[pl - 1] / 10, now -= s[pl - 1] / 10;
chkmin(ans, tmp + max(0ll, s[n] - s[i] - now));
}
}
printf("%lld\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
int n;
int a[MAXN];
int dp[MAXN + 1][31];
void upd(int &a, int b) {
if (a == -1 || b > a) a = b;
}
void run() {
scanf("%d", &n);
for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
int sum = 0;
for (int i = (0); i < (n); ++i) sum += a[i];
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = (0); i < (n); ++i)
for (int j = (0); j <= (30); ++j)
if (dp[i][j] != -1) {
int x = a[i] / 1000;
if (j + x <= 30) upd(dp[i + 1][j + x], dp[i][j]);
int d = min(10 * x, j);
upd(dp[i + 1][j - d], dp[i][j] + d);
}
int mx = -1;
for (int j = (0); j <= (30); ++j) upd(mx, dp[n][j]);
int ret = sum - 100 * mx;
printf("%d\n", ret);
}
int main() {
run();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch = getchar();
long long x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
long long n, ans = (1ll << 60), f[300005][35];
int main() {
n = read();
memset(f, 7, sizeof f);
f[0][0] = 0;
for (long long i = 0; i <= n - 1; ++i) {
long long x = read() / 100;
for (long long j = 0; j <= 31; ++j)
f[i + 1][j + x / 10] = min(f[i + 1][j + x / 10], f[i][j] + x);
for (long long j = 1; j <= 31; ++j)
f[i + 1][j - min(x, j)] =
min(f[i + 1][j - min(x, j)], f[i][j] + x - min(x, j));
}
for (long long i = 0; i <= 31; ++i) ans = min(ans, f[n][i]);
printf("%lld\n", ans * 100);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
int mod = (int)1e9 + 7;
const int logN = 18;
const int inf = 1e9 + 9;
const int N = 4e5 + 6;
int dp[N][105], a[N], n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int x = n; x >= 1; x--) {
for (int got = 50; got >= 0; got--) {
dp[x][got] = dp[x + 1][got + a[x] / 1000] + a[x];
if (got >= a[x] / 100)
dp[x][got] = min(dp[x][got], dp[x + 1][got - a[x] / 100]);
else
dp[x][got] = min(dp[x][got], dp[x + 1][0] + a[x] - got * 100);
}
for (int got = 51; got <= 100; got++) dp[x][got] = inf;
}
cout << dp[1][0] << '\n';
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
if (fu) v = -v;
}
const int INF = 1e9 + 10;
int n, a[500010], f[300010][111], ans;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) getint(a[i]), a[i] /= 100;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= 100; ++j) f[i][j] = INF;
f[0][0] = 0;
for (int i = 0; i <= n - 1; ++i)
for (int j = 0; j <= 100; ++j)
if (f[i][j] < INF) {
f[i + 1][j - min(j, a[i + 1])] =
min(f[i + 1][j - min(j, a[i + 1])],
f[i][j] + a[i + 1] - min(j, a[i + 1]));
f[i + 1][j + a[i + 1] / 10] =
min(f[i + 1][j + a[i + 1] / 10], f[i][j] + a[i + 1]);
}
ans = INF;
for (int j = 0; j <= 100; ++j) ans = min(ans, f[n][j]);
cout << ans * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int ar[N], num1, num2, n;
vector<int> pos[2];
struct node {
int sum, minpre;
};
node it[N << 2];
void tag(int idx, int l, int r) {
if (l < r) {
it[idx].sum = it[2 * idx].sum + it[2 * idx + 1].sum;
it[idx].minpre =
min(it[2 * idx].minpre, it[2 * idx].sum + it[2 * idx + 1].minpre);
}
}
void init(int idx, int l, int r) {
if (l == r) {
it[idx].sum = it[idx].minpre = -ar[l];
return;
}
init(2 * idx, l, (l + r) / 2);
init(2 * idx + 1, (l + r) / 2 + 1, r);
tag(idx, l, r);
}
void upd(int idx, int l, int r, int pos1, int val) {
if (l > pos1 || r < pos1) {
return;
}
if (l == r) {
it[idx].sum = it[idx].minpre = val;
return;
}
upd(2 * idx, l, (l + r) / 2, pos1, val);
upd(2 * idx + 1, (l + r) / 2 + 1, r, pos1, val);
tag(idx, l, r);
}
bool check(int val) {
init(1, 1, n);
int cnt, sum, now;
for (int i = 0; i <= num1; i++) {
if (val < i * 1000) {
break;
}
if (i) {
upd(1, 1, n, pos[0][i - 1], 100);
}
if (i == 0) {
cnt = min(val / 2000, num2);
for (int j = 0; j < cnt; j++) {
upd(1, 1, n, pos[1][j], 200);
}
sum = val - i * 1000 - cnt * 2000;
if (sum + it[1].minpre >= 0) {
return true;
}
continue;
}
now = min((val - i * 1000) / 2000, num2);
while (cnt > now) {
cnt--;
upd(1, 1, n, pos[1][cnt], -2000);
}
sum = val - i * 1000 - cnt * 2000;
if (sum + it[1].minpre >= 0) {
return true;
}
}
return false;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int lef = 0, rig = 6e8, mid, i, j, k, l;
cin >> n;
num1 = num2 = 0;
for (i = 1; i <= n; i++) {
cin >> ar[i];
if (ar[i] == 1000) {
num1++;
pos[0].push_back(i);
} else {
num2++;
pos[1].push_back(i);
}
}
while (rig > lef) {
mid = (lef + rig) >> 1;
if (check(mid)) {
rig = mid;
} else {
lef = mid + 1;
}
}
cout << lef;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005, M = 30;
int a[N], f[N][M + 5], j, n, i, ans, t;
inline void up(int& a, int b) {
if (!a || a > b) a = b;
}
int main() {
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", a + i), a[i] /= 100;
for (i = 0; i < n; ++i)
for (j = 0; j <= M; ++j)
if (f[i][j] || (!i && !j)) {
up(f[i + 1][j + a[i + 1] / 10], f[i][j] + a[i + 1]);
t = min(j, a[i + 1]);
up(f[i + 1][j - t], f[i][j] + a[i + 1] - t);
}
for (i = 0; i <= M; ++i)
if (f[n][i]) up(ans, f[n][i]);
printf("%d\n", ans * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
if (y < x) x = y;
}
int dp[2][60];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= 41; i++) dp[0][i] = -1e9;
int sum = 0;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
x /= 100;
sum += x;
int now = i & 1;
for (int j = 0; j <= 41; j++) dp[now][j] = -1e9;
for (int j = 0; j <= 41 - x / 10; j++)
chkmax(dp[now][j + x / 10], dp[!now][j]);
for (int j = 0; j <= 41; j++)
chkmax(dp[now][max(j - x, 0)], dp[!now][j] + min(j, x));
for (int j = 40; j >= 0; j--) chkmax(dp[now][j], dp[now][j + 1]);
}
int ans = 0;
for (int j = 0; j <= 41; j++) chkmax(ans, dp[n & 1][j]);
cout << (sum - ans) * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 300007;
const int INF = 2.1e9;
const int MOD = 1e9 + 7;
const double dif = 1e-7;
const double PI = 3.14159265358979323846;
int n, m, k, sum = 0;
int a[maxn], pre[maxn];
bool check(int x) {
int d = sum - k, s = 0, flag1 = 0, flag2 = 0;
if (d > k / 10) return false;
int i;
for (i = n; i >= 1; i--) {
if (s >= d) break;
s += a[i];
if (a[i] == 10) flag1 = 1;
if (a[i] == 20) flag2 = 1;
}
if (pre[i] >= d * 10)
return true;
else if (flag1 && s - d >= 10 && d * 10 - pre[i] <= 10)
return true;
else if (flag2 && d * 10 - pre[i] <= 10) {
for (; i >= 1; i--)
if (a[i] == 10) return pre[i - 1] >= 100;
}
return false;
}
int main(void) {
while (cin >> n) {
pre[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] /= 100;
pre[i] = pre[i - 1] + a[i];
}
sum = pre[n];
k = sum / 11 * 10;
while (!check(k)) k++;
cout << k * 100 << endl;
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, ans, two, one, l, r, k, a[N], dp[N][205];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] /= 100;
}
memset(dp, 127, sizeof(dp));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 200; j++)
if (dp[i][j] <= 2e8) {
if (j + a[i + 1] / 10 <= 200)
dp[i + 1][j + a[i + 1] / 10] =
min(dp[i + 1][j + a[i + 1] / 10], dp[i][j] + a[i + 1]);
if (j >= a[i + 1])
dp[i + 1][j - a[i + 1]] = min(dp[i + 1][j - a[i + 1]], dp[i][j]);
else
dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + (a[i + 1] - j));
}
}
int ans = 2e9;
for (int i = 0; i <= 200; i++) {
ans = min(ans, dp[n][i]);
}
printf("%d00\n", ans);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[300005];
long long dp[300005][105];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (long long(i) = (1); (i) <= (n); (i)++) cin >> a[i], a[i] /= 100;
for (long long(i) = (0); (i) <= (n); (i)++)
for (long long(j) = (0); (j) <= (100); (j)++) dp[i][j] = 1e18;
dp[0][0] = 0;
for (long long(i) = (0); (i) <= (n - 1); (i)++) {
for (long long(j) = (0); (j) <= (100); (j)++) {
long long x = min(j, a[i + 1]);
(dp[i + 1][j - x]) = min((dp[i + 1][j - x]), (dp[i][j] + a[i + 1] - x));
if (j + a[i + 1] / 10 <= 100)
(dp[i + 1][j + a[i + 1] / 10]) =
min((dp[i + 1][j + a[i + 1] / 10]), (dp[i][j] + a[i + 1]));
}
}
long long ans = 1e18;
for (long long(i) = (0); (i) <= (100); (i)++) (ans) = min((ans), (dp[n][i]));
cout << ans * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long linf = 1ll * inf * inf;
const int N = 300000 + 7;
const int M = 32;
const int multipleTest = 0;
int dp[N][M];
int n;
int a[N];
void solve() {
cin >> n;
for (int i = (0), _b = (N); i < _b; ++i)
for (int j = (0), _b = (M); j < _b; ++j) dp[i][j] = inf;
dp[0][0] = 0;
for (int i = (1), _b = (n + 1); i < _b; ++i) {
int u;
scanf("%d", &u);
u /= 100;
for (int j = 0; j < M; ++j) {
for (int t = 1, _m = min(u, j); t <= _m; ++t)
dp[i][j - t] = min(dp[i][j - t], dp[i - 1][j] + u - t);
if (j + u / 10 < M)
dp[i][j + u / 10] = min(dp[i][j + u / 10], dp[i - 1][j] + u);
}
}
int res = inf;
for (int j = (0), _b = (M); j < _b; ++j) res = min(res, dp[n][j]);
cout << res * 100;
}
int main() {
int Test = 1;
if (multipleTest) {
cin >> Test;
}
for (int i = 0; i < Test; ++i) {
solve();
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
const int maxn = 3e5 + 10;
long long dp[maxn][55], a[maxn];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
a[i] /= 100;
}
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 42; j++) dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = a[i] / 10; j <= 40; j++) {
dp[i][j] = min(dp[i - 1][j - a[i] / 10] + a[i], dp[i][j]);
}
for (int j = 0; j <= 40; j++) {
for (int k = 1; k <= a[i] && j + k <= 40; k++)
dp[i][j] = min(dp[i - 1][j + k] + a[i] - k, dp[i][j]);
}
}
long long ans = inf;
for (int i = 0; i <= 20; i++) ans = min(ans, dp[n][i]);
cout << ans * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long a[300100];
long long sum[300100];
int main() {
long long ans = 0;
int flag1 = 0, flag2 = 0;
memset(a, 0, sizeof(a));
memset(sum, 0, sizeof(sum));
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] != 1000) flag1 = 1;
if (a[i] != 2000) flag2 = 1;
}
sum[0] = a[0];
for (int i = 1; i < n; i++) {
sum[i] = a[i] + sum[i - 1];
}
if (flag2 == 0) {
int temp = sum[n - 1] % 22000;
temp /= 2000;
int v = sum[n - 1] / 22000;
ans = v * 20000 + (temp - 1) * 0.9 * 2000 + 2000;
} else if (flag1 == 0) {
int temp = sum[n - 1] % 11000;
temp /= 1000;
int v = sum[n - 1] / 11000;
ans = v * 10000 + (temp - 1) * 0.9 * 1000 + 1000;
} else {
if (sum[n - 1] > 22000) {
int v = sum[n - 1] / 1100;
ans = sum[n - 1] - v * 100;
} else {
if (a[n - 1] == 2000 || sum[n - 1] <= 11000)
ans = sum[n - 1] - sum[n - 2] / 10;
else
ans = sum[n - 1] - sum[n - 2] / 10 + 100;
}
}
cout << ans;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long a[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> a[i];
a[i] /= 100;
}
long long dp[n + 1][35];
dp[0][0] = 0;
for (long long i = 1; i < 35; i++) dp[0][i] = 1000000000000;
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j < 35; j++) {
dp[i][j] = 1000000000000;
for (long long k = 1; k <= a[i]; k++) {
if ((k + j) >= 35) goto here;
dp[i][j] = min(dp[i][j], dp[i - 1][j + k] + a[i] - k);
}
here:
if ((j - a[i] / 10) >= 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j - (a[i] / 10)] + a[i]);
}
}
long long ans = 1000000000000;
for (long long j = 0; j < 35; j++) ans = min(ans, dp[n][j]);
ans *= 100;
cout << ans << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 300033, max_m = 41, inf = 1011111111;
int n, a[max_n], dp[2][max_m];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
a[i] /= 100;
}
int q1 = 0, q2 = 1;
for (int j = 0; j < max_m; ++j) {
dp[q1][j] = inf;
}
dp[q1][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < max_m; ++j) {
dp[q2][j] = inf;
}
for (int j = 0; j < max_m; ++j) {
if (dp[q1][j] == inf) {
continue;
}
if (j + a[i] / 10 < max_m) {
dp[q2][j + a[i] / 10] = min(dp[q2][j + a[i] / 10], dp[q1][j] + a[i]);
}
int y = min(j, a[i]);
dp[q2][j - y] = min(dp[q2][j - y], dp[q1][j] + a[i] - y);
}
swap(q1, q2);
}
int ans = inf;
for (int i = 0; i < max_m; ++i) {
ans = min(ans, dp[q1][i]);
}
printf("%d\n", ans * 100);
return 0;
}
| 10 | CPP |