Dreamoon Likes Coloring 【CF 1329 A】 (4)

说明我们无法完成满足题意的染色,因为我们前面是尽可能少的染色切满足题目要求,如果仍然无法满足,说明没有可行解。

1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 #include <vector> 8 #include <cstring> 9 #include <functional> 10 #define LL long long 11 using namespace std; 12 13 const int N = 1e5 + 10; 14 int L[N], inx[N]; 15 16 void solve () 17 { 18 int n, m, len; 19 scanf("%d%d", &n, &m); 20 21 LL Sum_d = 0; 22 for(int i = 1; i <= m; ++i) { 23 scanf("%d", L + i); 24 Sum_d += L[i]; 25 } 26 27 int pre_s, pre_d; 28 pre_s = 1; pre_d = 0; 29 len = n; 30 for(int i = 1; i <= m; ++i) { 31 //printf("start = %d L = %d\n", pre_s + pre_d, n - L[i] + 1); 32 if(n - L[i] + 1 < pre_s + pre_d) { break; } 33 34 if(Sum_d - L[i] >= len - 1) { 35 Sum_d -= L[i]; 36 len -= 1; 37 pre_s = pre_s + pre_d; 38 pre_d = 1; 39 } else { 40 int tmp_d = (len - 1) - (Sum_d - L[i]); 41 if(tmp_d + 1 > L[i]) { break; } 42 Sum_d -= L[i]; 43 len -= (1 + tmp_d); 44 pre_s = pre_s + pre_d; 45 pre_d = (1 + tmp_d); 46 } 47 inx[i] = pre_s; 48 } 49 50 // cout << "len = " << len << endl; 51 52 if(len > 0) { 53 printf("-1\n"); 54 } else{ 55 for(int i = 1; i <= m; ++i) { printf("%d ", inx[i]); } 56 printf("\n"); 57 } 58 59 60 } 61 62 int main() 63 { 64 solve(); 65 66 return 0; 67 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zysjyw.html