Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream f("raft.in");
- ofstream g("raft.out");
- int d,r,c,rr,i,x1,x2,y,n,x3,h[500],sh[500];
- int main()
- {
- f >> c >> rr >> n;
- for(i = 1; i <= n; ++i)
- {
- f >> d >> r;
- if(r > h[d])
- h[d] = r;
- }
- sh[1] = h[1];
- sh[2] = max(h[1], h[2]);
- sh[3] = max(sh[2], h[3]);
- for(i = 4; i <= c; ++i)
- {
- x1 = h[i] + sh[i - 1];
- x2 = max(h[i], h[i - 1]) + sh[i - 2];
- y = x2 - sh[i - 2];
- x3 = max(y, h[i - 2]) + sh[i - 3];
- sh[i] = min(x1, x2);
- sh[i] = min(sh[i], x3);
- }
- g << sh[c] << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement