zoukankan      html  css  js  c++  java
  • Codeforces #631 Dreamoon Likes Coloring

    直接倒着放,然后在正着平移,使得铺满n

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    
    const int maxn = 1e5 + 5;
    
    int t, n, m, a[maxn], b[maxn];
    
    int main()
    {
        cin >> n >> m;
        int k = n - m;
        ll sum = 0;
        for (int i = 1; i <= m; ++i) cin >> a[i], sum += a[i];
        if (sum < n) {puts("-1"); return 0;}
        b[m] = n - a[m] + 1;
        for (int i = m - 1; i; --i)
        {
            b[i] = b[i + 1] - 1;
            if (n - b[i] + 1 < a[i]) b[i] = n - a[i] + 1;
        }
        if (b[1] < 1) {puts("-1"); return 0;}
        if (b[1] != 1)
        {
            b[1] = 1;
            for (int i = 2; i <= m; ++i)
                if (b[i] - b[i - 1] > a[i - 1]) b[i] = b[i - 1] + a[i - 1];
                else break;
        }
        for (int i = 1; i <= m; ++i) cout << b[i] << ' ';
        return 0;
    }
    

      

  • 相关阅读:
    IOS之UIKit_Day13
    IOS之UIKit_Day12
    IOS之UIKit_Day11
    IOS之UIKit_Day10
    iOS设计模式之工厂模式
    常用操作
    盒子模式
    block循环使用问题
    IOS-sqlite3
    IOS-View用作控制器
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/12640244.html
Copyright © 2011-2022 走看看