fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int n,q,t,k,d;
  6. int Time[105],stmp,cnt;
  7.  
  8. int main()
  9. {
  10. // freopen("nhap.inp", "r", stdin);
  11. cin>>n>>q;
  12. for (int i=1; i <= q; i++)
  13. {
  14. scanf("%d %d %d",&t,&k,&d);
  15. stmp=cnt=0;
  16. for (int j=1; j<=n; j++)
  17. if (Time[j]<=t) cnt++;
  18. if (cnt<k) { printf("-1\n"); continue; }
  19. cnt=0;
  20. for (int j=1; j<=n; j++)
  21. {
  22. if (Time[j]<=t)
  23. {
  24. stmp+=j;
  25. Time[j]=t+d;
  26. cnt++;
  27. if (cnt==k) break;
  28. }
  29. }
  30. printf("%d\n",stmp);
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty