Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 – Final Round Div. 2 Edition), problem: (D) Travel Card Solution in C/C++

#include <stdio.h>

#define SIZE 100010

struct ride {
int cost, t;
} r[SIZE];

int main()
{
int i, j, n;
scanf(“%d”, &n);

r[0].t = r[0].cost = 0;

for (i = 1; i <= n; i++)
{
scanf(“%d”, &r[i].t);
r[i].cost = r[i – 1].cost + 20;

for (j = i; j > 0 && (r[j].t + 90 > r[i].t); j–)
if (r[j – 1].cost + 50 < r[i].cost)
r[i].cost = r[j – 1].cost + 50;

for (j = i; j > 0 && (r[j].t + 1440 > r[i].t); j–)
if (r[j – 1].cost + 120 < r[i].cost)
r[i].cost = r[j – 1].cost + 120;

printf(” %d\n”, r[i].cost – r[i – 1].cost);
}

return 0;
}

#include <stdio.h>

#define SIZE 100010

struct ride {
int cost, t;
} r[SIZE];

int main()
{
int i, j, n;
scanf(“%d”, &n);

r[0].t = r[0].cost = 0;

for (i = 1; i <= n; i++)
{
scanf(“%d”, &r[i].t);
r[i].cost = r[i – 1].cost + 20;

for (j = i; j > 0 && (r[j].t + 90 > r[i].t); j–)
if (r[j – 1].cost + 50 < r[i].cost)
r[i].cost = r[j – 1].cost + 50;

for (j = i; j > 0 && (r[j].t + 1440 > r[i].t); j–)
if (r[j – 1].cost + 120 < r[i].cost)
r[i].cost = r[j – 1].cost + 120;

printf(” %d\n”, r[i].cost – r[i – 1].cost);
}

return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

How to Use Snail Mucin Essence on Face (Complete Beginner’s Guide)

Overview: How to Use Snail Mucin Essence on Face (Complete Beginner's Guide) Finding reliable, data-backed guidance on how to use snail mucin essence on face...

How to Use Cosrx Snail Mucin at Night (Complete Beginner’s Guide)

Overview: How to Use Cosrx Snail Mucin at Night (Complete Beginner's Guide) Finding reliable, data-backed guidance on how to use cosrx snail mucin at night...

How to Use Cosrx Snail Mucin Moisturizer (Complete Beginner’s Guide)

Overview: How to Use Cosrx Snail Mucin Moisturizer (Complete Beginner's Guide) Finding reliable, data-backed guidance on how to use cosrx snail mucin moisturizer can be...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!