Fair 2

Fair simulation questions 2

day1t1

1 without the \ (n * mnm \) is reduced to zero, the down enough \ (K \) can.
2. If \ (the n-\) , \ (m \) where a is 1, the answer is \ (- 1 \) , will be irrelevant sentenced \ (RE \) , I do not know why.
3. The queue may be repeating elements, going about weight.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define LL long long 
using namespace std;
priority_queue<LL> q;
LL n,m,k,ansp,last,cnt;
void cutn(LL u)
{
    while(u>n)
    {
        u-=n;
        q.push(u),++cnt;
    }
    return ;
}
void cutm(LL u)
{
    while(u>m)
    {
        u-=m;
        q.push(u);
    }
    return ;
}
int main()
{
    freopen("day1t1.in","r",stdin);
    freopen("day1t1.out","w",stdout);
    scanf("%lld%lld%lld",&n,&m,&k);
    if(n==1||m==1) { printf("-1\n"); return 0;}
    ansp=n*m-n-m;
//  q.push(ansp);
    for(int i=0;i<=500;i++)
     for(int j=0;j<=500;j++)
      if((ansp-i*n-j*m)>0) q.push(ansp-i*n-j*m);
//  cutn(ansp); cutm(ansp);
//  ansp-=n;
//  while(ansp>m)
//  {
//      cutm(ansp);
//      ansp-=n;
//  }
//  while(ansp>0)
//  {
//      ansp-=n;
//      q.push(ansp);
//      q.push(ansp+n-m);
//  }
    for(int i=1;i<k;i++)
    {
//      cout<<q.top()<<"*";
        if(q.top()==last) ++i;
        if(q.empty()) { printf("-1\n"); return 0;}
        q.pop();
    }
    ansp=q.top();
    printf("%lld\n",ansp);
    return 0;
}

80days

Ideas :( Oh, first determine what is -1, if all add up together, along with \ (c \) is less than zero, then that is \ (--1 \) a) open an array of records about the prefix and then open two arrays recorded at the minimum prefix and suffix minimum. From small to large judgment to \ (i \) as a starting point if feasible, feasible output end.

If the first \ (I \) points feasible as a starting point, then satisfied ( \ (C + \) shown): the prefix and suffix subtracting the minimum value is greater than the minimum value 0 and the prefix plus all numbers greater than 0 and back.

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
const int N = 1e6+5;
const LL inf = 1e15+9;
LL T,n,a[N],b[N],c,sum;
LL cnt[N],pre[N],suf[N];
bool flag;
inline LL read()
{
    char c=getchar();
    LL ans=0,w=1;
    while((c<'0'||c>'9')&&c!='-') c=getchar();
    if(c=='-') { w=-1; c=getchar(); }
    while(c>='0'&&c<='9')
    { ans=ans*10+c-'0'; c=getchar(); }
    return ans*w;
}
int main()
{
    T=read();
    while(T--)
    {
        flag=0;
        n=read(); c=read();
        sum=0; cnt[0]=0;
        pre[0]=inf; suf[n+1]=inf;
        for(int i=1;i<=n;i++)
         a[i]=read();
        for(int i=1;i<=n;i++)
        {
            b[i]=read();
            a[i]-=b[i]; sum+=a[i];
            cnt[i]=cnt[i-1]+a[i];
            pre[i]=min(pre[i-1],cnt[i]);
        }
        for(int i=n;i>=1;i--)
         suf[i]=min(suf[i+1],cnt[i]);
        if(sum+c<0) { printf("-1\n"); continue; }
        if(suf[1]+c>0) printf("1 ");
        for(int i=2;i<=n;i++)
        {
            if(a[i]+c<0||flag) continue;
            if(suf[i]+c>=cnt[i-1]&&pre[i-1]+sum-cnt[i-1]+c>=0)
             printf("%d ",i),flag=1;
        }
    }
    return 0;
} 

Guess you like

Origin www.cnblogs.com/karryW/p/10993935.html