Pagini recente » Cod sursa (job #2526776) | Cod sursa (job #467815) | Cod sursa (job #2966023) | Cod sursa (job #2739462) | Cod sursa (job #2814256)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
void read_uint32_t(FILE *__restrict stream, uint32_t *__restrict nr) {
uint8_t ch;
*nr = 0;
while ((ch = fgetc(stream)) && ('0' <= ch && ch <= '9')) {
*nr *= 10;
*nr += ch - '0';
}
if (ch == '\r') {
fgetc(stream);
}
}
struct oras {
uint32_t pos;
uint32_t d;
};
int comp(const void *o1, const void *o2) {
return ((struct oras *)(o1))->pos > ((struct oras *)(o2))->pos;
}
struct oras a[50000];
uint32_t n, m;
int main(void) {
{
FILE *__restrict in = fopen("orase.in", "r");
read_uint32_t(in, &m);
read_uint32_t(in, &n);
{
int32_t i;
uint32_t x, y;
for(i = 0; i < n; ++i) {
read_uint32_t(in, &x);
read_uint32_t(in, &y);
a[i].pos = x;
a[i].d = y;
}
}
fclose(in);
}
qsort(a, n, sizeof(struct oras), comp);
int32_t sm = INT32_MIN;
int32_t sl;
{
int32_t i;
if (n == 1) {
sm = INT32_MIN;
sl = 0;
} else {
sm = 0;
sl = 0;
for(i = 0; i < n - 1; ++i) {
if (a[i].d - a[i].pos > sm - sl) { /** a[i].d + a[i + 1].d + (a[i + 1].pos - a[i].pos) > sm + a[i + 1].d + (a[i + 1].pos - sl) **/
sm = a[i].d;
sl = a[i].pos;
}
}
}
}
{
FILE *__restrict out = fopen("orase.out", "w");
if (sm == INT32_MIN) {
fputs("0", out);
} else {
fprintf(out, "%u", sm + a[n-1].d + (a[n-1].pos - sl));
}
fclose(out);
}
return 0;
}