Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("raft.in");
  4. ofstream g("raft.out");
  5. int d,r,c,rr,i,x1,x2,y,n,x3,h[500],sh[500];
  6. int main()
  7. {
  8. f >> c >> rr >> n;
  9. for(i = 1; i <= n; ++i)
  10. {
  11. f >> d >> r;
  12. if(r > h[d])
  13. h[d] = r;
  14. }
  15. sh[1] = h[1];
  16. sh[2] = max(h[1], h[2]);
  17. sh[3] = max(sh[2], h[3]);
  18. for(i = 4; i <= c; ++i)
  19. {
  20. x1 = h[i] + sh[i - 1];
  21. x2 = max(h[i], h[i - 1]) + sh[i - 2];
  22. y = x2 - sh[i - 2];
  23. x3 = max(y, h[i - 2]) + sh[i - 3];
  24. sh[i] = min(x1, x2);
  25. sh[i] = min(sh[i], x3);
  26. }
  27. g << sh[c] << '\n';
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement