标签:
Description
Input
Output
Sample Input
Sample Output
#include <iostream> using namespace std; int n; long long s; long long a[100005],t[100005]; void fun(long long *a,int x,int y,long long*t) { if(y-x>1) { int m=x+(y-x)/2; int p=x,q=m,i=x; fun(a,x,m,t); fun(a,m,y,t); while(p<m||q<y) { if(q>=y||(a[p]<=a[q]&&p<m)) t[i++]=a[p++]; else { t[i++]=a[q++]; s=s+m-p; } } for( i=x;i<y;i++) a[i]=t[i]; } } int main() { long long k; while(cin>>n>>k) { s=0; for(int i=0;i<n;i++) cin>>a[i]; fun(a,0,n,t); if(s-k<=0) cout<<"0"<<endl; else cout<<s-k<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/xinxiangqing/p/4713270.html