/*input
6
1 2
0 0
2 0
0 0
0 0
0 1
*/
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<typename A, typename B>
using omap = tree <A, B, less<A>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename A>
using oset = tree <A, null_type, less<A>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
ll ran(ll a, ll b)
{
//return a + (ll)(rng() % (b - a + 1));
return uniform_int_distribution<ll>(a, b)(rng);
}
ll power(ll x, ll p)
{
if (abs(x) >= mod)
x %= mod;
if (x < 0)
x += mod;
if (abs(p) >= mod - 1)
p %= mod - 1;
if (p < 0)
p += mod - 1;
ll r = 1;
while (p)
{
if (p % 2)
r = (r * x) % mod;
x = (x * x) % mod;
p /= 2;
}
return r;
}
void solve()
{
int N;
cin >> N;
int a[N];
for (int i = 0; i < N; i++)
{
int f, b;
cin >> f >> b;
a[i] = f - b;
}
int S = 30000;
vector<ll> dp(2 * S + 1, 1e17);
for (int i = 0; i <= S; i++)
dp[i + S] = 0;
vector<ll> dp1(2 * S + 1);
for (int i = 0; i < N; i++)
{
ll mn = 1e17;
for (int x = -S; x <= S; x++)
{
int y = min(S, x + a[i]);
if (y >= -S)
mn = min(mn, abs(x) + dp[y + S]);
dp1[x + S] = mn;
}
dp = dp1;
}
cout << dp[S] << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
338 ms |
1288 KB |
Output is correct |
3 |
Incorrect |
352 ms |
1300 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
338 ms |
1288 KB |
Output is correct |
3 |
Incorrect |
352 ms |
1300 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
338 ms |
1288 KB |
Output is correct |
3 |
Correct |
2 ms |
1220 KB |
Output is correct |
4 |
Correct |
116 ms |
1272 KB |
Output is correct |
5 |
Correct |
188 ms |
1272 KB |
Output is correct |
6 |
Correct |
338 ms |
1288 KB |
Output is correct |
7 |
Correct |
341 ms |
1280 KB |
Output is correct |
8 |
Correct |
361 ms |
1288 KB |
Output is correct |
9 |
Correct |
333 ms |
1280 KB |
Output is correct |
10 |
Correct |
358 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
338 ms |
1288 KB |
Output is correct |
3 |
Incorrect |
352 ms |
1300 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
338 ms |
1288 KB |
Output is correct |
3 |
Incorrect |
352 ms |
1300 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |