Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

 
 
 
 
Основное
 
 
Отправитель Задача Язык Вердикт Время Память Отослано Протест.  
247708457 Дорешивание:
DisconnectedGraph
1430F - 14 C++17 (GCC 9-64) Полное решение 31 мс 68 КБ 2024-02-22 10:42:21 2024-02-22 10:42:21
→ Исходный код
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;

int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); } 
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); } 
int n = in(), k = in();
const int kN = 2050;
struct Wave { int l, r, a; } a[kN];
ll f[kN];
int main() { 
	ll tot = 0;
	_rep(i,1,n) {
		a[i].l = in(), a[i].r = in(), a[i].a = in();
		tot += a[i].a;
	}
	for(int i = n; i; --i) {
		f[i] = (a[i].a - 1ll * k * (a[i].r - a[i].l) + (a[i].r == a[i + 1].l) * f[i + 1]);
		f[i] = max(f[i], 0ll);
	}
	int cur = 0;
	_rep(i,1,n) {
		if(cur < f[i]) tot += cur, cur = k;
		if(cur < f[i]) {
			puts("-1");
			return 0;
		}
		cur = (cur - a[i].a % k + k) % k;
	}
	outln(tot);
	return 0;
}

/* 
a list of keywords
clear empty push_back pop_back push pop top front back
emplace_back emplace push_front pop_front insert erase
find count set reset bitset map vector string multiset
first second iterator prev next deque multimap reverse
sort begin end list modify query init check calc prime
putchar getchar puts scanf printf max min swap replace
make_pair make_tuple numeric_limits auto function null
*/
?
Время: ? ms, память: ? КБ
Вердикт: ?
Ввод
?
Вывод участника
?
Ответ жюри
?
Комментарий чекера
?
Диагностика
?
Показать детали тестирования