Cod sursa(job #243898)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const char iname[] = "stergeri.in";
const char oname[] = "stergeri.out";
vector <pair <int, int> > V;
int main(void)
{
ifstream in(iname);
ofstream out(oname);
int N, M, K;
int a, b;
in >> N >> M >> K;
for (int i = 0; i < M; ++ i) {
in >> a >> b;
V.push_back(make_pair(a, b));
}
for (int i = M - 1; i >= 0; -- i) {
a = V[i].first, b = V[i].second;
if (a <= K)
K += b-a+1;
}
out << K;
in.close(), out.close();
return 0;
}