Lucian_Adrian

Untitled

Jan 25th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream cin("furnica.in");
  4. ofstream cout("furnica.out");
  5. struct foaie{
  6. long long l, h;
  7. }a[10005];
  8. long long cer, n, t;
  9. int main(){
  10. cin >> cer;
  11. if(cer == 1 || cer == 2){
  12. cin >> n;
  13. for(int i = 1; i <= n; ++i)
  14. cin >> a[i].l >> a[i].h;
  15. if(cer == 1){
  16. long long sum = a[1].h * 5;
  17. for(int i = 1; i <= n; ++i){
  18. sum += 3 * a[i].l;
  19. if(a[i].h > a[i+1].h)
  20. sum += 2 * (a[i].h - a[i+1].h);
  21. else
  22. sum += 5 * (a[i+1].h - a[i].h);
  23. }
  24. cout << sum;
  25. }
  26. else{
  27. long long sum = a[1].h;
  28. long long smax = 0;
  29. for(int i = 1; i <= n; ++i){
  30. sum += a[i].l;
  31. if(a[i].h > a[i+1].h){
  32. if(smax < sum)
  33. smax = sum;
  34. sum = 0;
  35. continue;
  36. }
  37. else
  38. sum += (a[i+1].h - a[i].h);
  39. }
  40. cout << smax;
  41. }
  42. }
  43. else{
  44. cin >> n >> t;
  45. for(int i = 1; i <= n; ++i)
  46. cin >> a[i].l >> a[i].h;
  47. long long sum = a[1].h * 5;
  48. for(int i = 1; i <= n; ++i){
  49. sum += 3 * a[i].l;
  50. if(sum >= t){
  51. cout << i;
  52. break;
  53. }
  54. if(a[i].h > a[i+1].h){
  55. sum += 2 * (a[i].h - a[i+1].h);
  56. if(sum >= t){
  57. cout << i;
  58. break;
  59. }
  60. }
  61. else{
  62. sum += 5 * (a[i+1].h - a[i].h);
  63. if(sum >= t){
  64. cout << i+1;
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment