#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define vel vector<long long>
#define V vector
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
int pr = 1000000007;
void uni(vel &a) {
vel ans(1, a[0]);
int n = a.size();
rep(i, n - 1) { if (a[i + 1] != a[i]) { ans.push_back(a[i + 1]); } }
a = ans;
}
int rui(int a, int n) {
if (n == 0) { return 1; }
int back = rui(a, n / 2);
back *= back; back %= pr;
if (n % 2 == 0) { return back; }
return (back*a) % pr;
}
int inv(int a) {
return rui(a, pr - 2);
}
signed main() {
int n, m; cin >> n >> m;
vel c(n+m);
vel p(n + m);
rep(i, m) {
cin >> p[i+1]; p[i+1]--;
cin >> c[i+1];
}
int INF = 600 * 600;
V<vel> cos(n+m, vel(301,INF*300));
V<vel> cos0 = cos, cos1 = cos;
for (int i = n + m - 1; i >= 0; i--) {
if (n <= i) {
rep(j, 300) { cos0[p[i]][j+ 1] += INF; }
rep(j, 301) { cos1[p[i]][j] += abs(c[i] - j); }
}
else {
rep(j, 301) {
rep(k, j) {
cos[i][j] = min(cos[i][j], cos0[i][k] + cos[i][j - k]);
}
}
if (i != 0) {
rep(j, 301) { cos0[p[i]][j] += cos[i][j]; }
rep(j, 301) { cos1[p[i]][j] += abs(c[i] - j); }
}
}
}
int ans = INF;
rep(i, 301) {
ans = min(ans, cos[0][i]);
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |