Advertisement
a53

Chimic

a53
Oct 19th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. int n,p[100001],P;
  4. struct interval
  5. {
  6. int s,d;
  7. };
  8. typedef interval INTERVAL;
  9. INTERVAL SD[100001];
  10.  
  11. void citire()
  12. {
  13. ifstream f("chimic.in");
  14. f>>n;
  15. for(int i=1;i<=n;++i)
  16. f>>p[i];
  17. for(int i=1;i<=n;++i)
  18. f>>SD[i].s>>SD[i].d;
  19. f.close();
  20. }
  21. int D[100001];
  22.  
  23. int maxim(int st,int dr)
  24. {
  25. int Max=D[st];
  26. for(int j=st;j<=dr;++j)
  27. if(D[j]>Max)
  28. Max=D[j];
  29. return Max;
  30. }
  31.  
  32. int main()
  33. {
  34. citire();
  35. ofstream g("chimic.out");
  36. for(int i=1;i<=n;++i)
  37. for(int j=1;j<=n;++j)
  38. if(SD[i].s==-1&&SD[i].d==-1)
  39. D[i]=p[i];
  40. else
  41. D[i]=p[i]+maxim(SD[i].s,SD[i].d);
  42. g<<D[n];
  43. g.close();
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement