Skip to content

Instantly share code, notes, and snippets.

@ctylim
Created October 13, 2015 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctylim/e5e335a26baaae74fd43 to your computer and use it in GitHub Desktop.
Save ctylim/e5e335a26baaae74fd43 to your computer and use it in GitHub Desktop.
Codeforces #325 div2 C
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
typedef long long ll;
using namespace std;
int inputValue(){
int a;
cin >> a;
return a;
}
template <typename T>
void output(T a, int precision) {
if(precision > 0){
cout << fixed << setprecision(precision) << a << "\n";
}
else{
cout << a << "\n";
}
}
// end of template
int main() {
// source code
int N = inputValue();
vector<int> V(N);
vector<int> D(N);
vector<ll> P(N);
rep(i, N){
cin >> V[i] >> D[i] >> P[i];
}
vector<int> C(N, 1);
ll disum = 0;
rep(i, N){
if (P[i] - disum >= 0) {
int tmp = V[i];
int j = i + 1;
while (j < N && tmp > 0) {
if (P[j] - disum >= 0 && C[j]) {
P[j] -= tmp;
tmp--;
if (P[j] < 0) {
C[j] = 0;
}
}
j++;
}
ll sum = disum;
int k = i + 1;
while (k < N){
if (P[k] - sum < 0) {
sum += D[k];
C[k] = 0;
}
k++;
}
}
else{
disum += D[i];
C[i] = 0;
}
}
int cnt = 0;
rep(i, N){
if (C[i]) {
cnt++;
}
}
output(cnt, 0);
rep(i, N){
if (C[i]) {
cout << i + 1 << " ";
}
}
output("", 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment