Cod sursa(job #81600)

Utilizator eferLiviu Ciortea efer Data 3 septembrie 2007 14:03:16
Problema Branza Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <utility>
#include <string>
using namespace std;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define REPV(i, a, b) for (int i = (a); i <= (b); ++i)
#define REPD(i, N) for (int i = (N)-1; i >= 0; --i)
#define REPVD(i, b, a) for (int i = (b); i >= (a); --i)
#define REPIT(it, v) for (it = (v).begin(); it != (v).end(); ++it)
#define SZ(a) ((int)(a).size())
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define MSET(a, v) memset((a), v, sizeof(a))
#define CPY(dest, source) memcpy(dest, source, sizeof(dest))

typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef map<int, int> MII;
typedef deque<int> QI;
typedef deque<PII> QPII;

int main() {
	freopen("branza.in", "rt", stdin);
	freopen("branza.out", "wt", stdout);

	int N, S, T;
	LL res = 0;

	scanf("%d %d %d", &N, &S, &T);

	deque<PII> Q;

	REP(i, N) {
		int c, p;
		scanf("%d %d", &p, &c);

		while (!Q.empty() && Q.front().Y + T < i) Q.pop_front();

		while (!Q.empty()) {
			PII off = Q.back();
			if (p > off.X + (i - off.Y) * S) break;
			Q.pop_back();
		}
		Q.PB(MP(p, i));

		res += (LL)c * (Q.front().X + (i - Q.front().Y) * S);
	}

	printf("%lld\n", res);

	return 0;
}