一个牛有N堆牌,每堆排数量不等。一只牛一次可以将第i堆到第j堆各打一张出去,问最少几次打完
想通了很简单
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s); #define ll long long #define pb push_back #define CLR(A,v) memset(A,v,sizeof A) ////////////////////////////////// #define inf 0x3f3f3f3f #define lson l,m,pos<<1 #define rson m+1,r,pos<<1|1 const int N=1e5+6; ll a[N],ans,n; int main() { RI(n);rep(i,1,n)cin>>(a[i]); rep(i,1,n) if(a[i]-a[i-1]>0) ans+=a[i]-a[i-1]; cout<<ans; return 0; }View Code